Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 313
Default Excel to text file

I want to export data from several cells into the text file and I am
epxeriencing problem with formatting, I can not have line breaks to give me
new line for each entry. I have tried to use Chr(10) and Chr(13) but it does
not work. What is wrong in code below:

=====================================
Sub PrintAttachments()

Dim AttachmentsList As String

CheckSecurity

AttachmentsList = ""

Application.ScreenUpdating = False

For i = 1 To 10
For j = 3 To 12
If Worksheets(i).Cells(j, 17) < "" Then
AttachmentsList = AttachmentsList + Worksheets(i).Cells(j,
17) & Chr(10)
End If
Next j
Next i
If AttachmentsList < "" Then
AttachmentsList = "List of attachments: " & Chr(10) & Chr(10) &
AttachmentsList
Open "c:\temp\attachments.txt" For Output As #1
Write #1, AttachmentsList
Close #1
End If

Application.ScreenUpdating = True

End Sub
=====================================

Is there any way of printing my results instead of saving them into txt file ?

Thanks for help.

Tony
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Excel to text file

First you shouldn't use write, instead use print. Write add double quotes to
the data while print doesn't both have the same syntax.

Second, write one line at a time. Print will add the carriage return and
line feed

Open "c:\temp\attachments.txt" For Output As #1

For i = 1 To 10
For j = 3 To 12
If Worksheets(i).Cells(j, 17) < "" Then
AttachmentsList = "List of attachments: " &
Worksheets(i).Cells(j, 17)
Write #1, AttachmentsList
End If
Next j
Next i
Close #1
End If


"Tony" wrote:

I want to export data from several cells into the text file and I am
epxeriencing problem with formatting, I can not have line breaks to give me
new line for each entry. I have tried to use Chr(10) and Chr(13) but it does
not work. What is wrong in code below:

=====================================
Sub PrintAttachments()

Dim AttachmentsList As String

CheckSecurity

AttachmentsList = ""

Application.ScreenUpdating = False

For i = 1 To 10
For j = 3 To 12
If Worksheets(i).Cells(j, 17) < "" Then
AttachmentsList = AttachmentsList + Worksheets(i).Cells(j,
17) & Chr(10)
End If
Next j
Next i
If AttachmentsList < "" Then
AttachmentsList = "List of attachments: " & Chr(10) & Chr(10) &
AttachmentsList
Open "c:\temp\attachments.txt" For Output As #1
Write #1, AttachmentsList
Close #1
End If

Application.ScreenUpdating = True

End Sub
=====================================

Is there any way of printing my results instead of saving them into txt file ?

Thanks for help.

Tony

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 313
Default Excel to text file

Hi Joel,

Thank you.

Tony

"Joel" wrote:

First you shouldn't use write, instead use print. Write add double quotes to
the data while print doesn't both have the same syntax.

Second, write one line at a time. Print will add the carriage return and
line feed

Open "c:\temp\attachments.txt" For Output As #1

For i = 1 To 10
For j = 3 To 12
If Worksheets(i).Cells(j, 17) < "" Then
AttachmentsList = "List of attachments: " &
Worksheets(i).Cells(j, 17)
Write #1, AttachmentsList
End If
Next j
Next i
Close #1
End If


"Tony" wrote:

I want to export data from several cells into the text file and I am
epxeriencing problem with formatting, I can not have line breaks to give me
new line for each entry. I have tried to use Chr(10) and Chr(13) but it does
not work. What is wrong in code below:

=====================================
Sub PrintAttachments()

Dim AttachmentsList As String

CheckSecurity

AttachmentsList = ""

Application.ScreenUpdating = False

For i = 1 To 10
For j = 3 To 12
If Worksheets(i).Cells(j, 17) < "" Then
AttachmentsList = AttachmentsList + Worksheets(i).Cells(j,
17) & Chr(10)
End If
Next j
Next i
If AttachmentsList < "" Then
AttachmentsList = "List of attachments: " & Chr(10) & Chr(10) &
AttachmentsList
Open "c:\temp\attachments.txt" For Output As #1
Write #1, AttachmentsList
Close #1
End If

Application.ScreenUpdating = True

End Sub
=====================================

Is there any way of printing my results instead of saving them into txt file ?

Thanks for help.

Tony

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 313
Default Excel to text file

Hi Joel,

How I can have it without quotation marks ???
Sample output file looks like:

=======================
"List of Attachments :"


"Attachments 1"
"Attachments 2"
=======================

Thank you.

Tony

"Joel" wrote:

First you shouldn't use write, instead use print. Write add double quotes to
the data while print doesn't both have the same syntax.

Second, write one line at a time. Print will add the carriage return and
line feed

Open "c:\temp\attachments.txt" For Output As #1

For i = 1 To 10
For j = 3 To 12
If Worksheets(i).Cells(j, 17) < "" Then
AttachmentsList = "List of attachments: " &
Worksheets(i).Cells(j, 17)
Write #1, AttachmentsList
End If
Next j
Next i
Close #1
End If


"Tony" wrote:

I want to export data from several cells into the text file and I am
epxeriencing problem with formatting, I can not have line breaks to give me
new line for each entry. I have tried to use Chr(10) and Chr(13) but it does
not work. What is wrong in code below:

=====================================
Sub PrintAttachments()

Dim AttachmentsList As String

CheckSecurity

AttachmentsList = ""

Application.ScreenUpdating = False

For i = 1 To 10
For j = 3 To 12
If Worksheets(i).Cells(j, 17) < "" Then
AttachmentsList = AttachmentsList + Worksheets(i).Cells(j,
17) & Chr(10)
End If
Next j
Next i
If AttachmentsList < "" Then
AttachmentsList = "List of attachments: " & Chr(10) & Chr(10) &
AttachmentsList
Open "c:\temp\attachments.txt" For Output As #1
Write #1, AttachmentsList
Close #1
End If

Application.ScreenUpdating = True

End Sub
=====================================

Is there any way of printing my results instead of saving them into txt file ?

Thanks for help.

Tony

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 313
Default Excel to text file

I have replaced write with print and now I have what I wanted. Thank you.

Tony

"Tony" wrote:

Hi Joel,

How I can have it without quotation marks ???
Sample output file looks like:

=======================
"List of Attachments :"


"Attachments 1"
"Attachments 2"
=======================

Thank you.

Tony

"Joel" wrote:

First you shouldn't use write, instead use print. Write add double quotes to
the data while print doesn't both have the same syntax.

Second, write one line at a time. Print will add the carriage return and
line feed

Open "c:\temp\attachments.txt" For Output As #1

For i = 1 To 10
For j = 3 To 12
If Worksheets(i).Cells(j, 17) < "" Then
AttachmentsList = "List of attachments: " &
Worksheets(i).Cells(j, 17)
Write #1, AttachmentsList
End If
Next j
Next i
Close #1
End If


"Tony" wrote:

I want to export data from several cells into the text file and I am
epxeriencing problem with formatting, I can not have line breaks to give me
new line for each entry. I have tried to use Chr(10) and Chr(13) but it does
not work. What is wrong in code below:

=====================================
Sub PrintAttachments()

Dim AttachmentsList As String

CheckSecurity

AttachmentsList = ""

Application.ScreenUpdating = False

For i = 1 To 10
For j = 3 To 12
If Worksheets(i).Cells(j, 17) < "" Then
AttachmentsList = AttachmentsList + Worksheets(i).Cells(j,
17) & Chr(10)
End If
Next j
Next i
If AttachmentsList < "" Then
AttachmentsList = "List of attachments: " & Chr(10) & Chr(10) &
AttachmentsList
Open "c:\temp\attachments.txt" For Output As #1
Write #1, AttachmentsList
Close #1
End If

Application.ScreenUpdating = True

End Sub
=====================================

Is there any way of printing my results instead of saving them into txt file ?

Thanks for help.

Tony

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I import text file of cash flow to excel file then use formula Bumpa Excel Discussion (Misc queries) 2 May 28th 10 04:22 PM
Saving multi-tab excel file created from comma delimited text file Marcus Aurelius Excel Programming 2 December 19th 05 05:16 PM
Excel VBA - open text file, replace text, save file? Cybert Excel Programming 2 October 2nd 04 01:05 AM
Import text file into excel with preset file layout, delimeters VBA meldrape Excel Programming 7 June 15th 04 08:31 PM
Open delimited text file to excel without changing data in that file zohanc Excel Programming 1 October 3rd 03 01:06 AM


All times are GMT +1. The time now is 08:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"