Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for write a txt file
Hi all,
Thanks to you all I've been improving in VBA so thanks again and great this forums exist. Now I have a doubt and I'm not sure how to do it, I want to write a txt file with the information of some cells separating them with commas. I have already use the worksheets.saveas function, the text file is generated correctly but I llike to see if there is any other option, maybe like the open function in order to write only the txt file. Do anyone have any idea for doing this? Thanks again |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for write a txt file
Are your cells in a contiguous range or are they scattered all around the
worksheet? If scattered all around, is there a regular pattern to them? It would help if you could tell us the range you are wanting to save. -- Rick (MVP - Excel) "japfvg" wrote in message ... Hi all, Thanks to you all I've been improving in VBA so thanks again and great this forums exist. Now I have a doubt and I'm not sure how to do it, I want to write a txt file with the information of some cells separating them with commas. I have already use the worksheets.saveas function, the text file is generated correctly but I llike to see if there is any other option, maybe like the open function in order to write only the txt file. Do anyone have any idea for doing this? Thanks again |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for write a txt file
Yes, you're right. Is a range like A1:D10 where I have the info to export.
Thanks "Rick Rothstein" wrote: Are your cells in a contiguous range or are they scattered all around the worksheet? If scattered all around, is there a regular pattern to them? It would help if you could tell us the range you are wanting to save. -- Rick (MVP - Excel) "japfvg" wrote in message ... Hi all, Thanks to you all I've been improving in VBA so thanks again and great this forums exist. Now I have a doubt and I'm not sure how to do it, I want to write a txt file with the information of some cells separating them with commas. I have already use the worksheets.saveas function, the text file is generated correctly but I llike to see if there is any other option, maybe like the open function in order to write only the txt file. Do anyone have any idea for doing this? Thanks again |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for write a txt file
Option Explicit
Sub pushdata() Dim cell As Range Dim txt As String For Each cell In Range("C5:D21") txt = txt & "," & cell.Text Next Open "C:\temp\data.txt" For Output As #1 Print #1, Mid(txt, 2) Close #1 End Sub "japfvg" wrote: Yes, you're right. Is a range like A1:D10 where I have the info to export. Thanks "Rick Rothstein" wrote: Are your cells in a contiguous range or are they scattered all around the worksheet? If scattered all around, is there a regular pattern to them? It would help if you could tell us the range you are wanting to save. -- Rick (MVP - Excel) "japfvg" wrote in message ... Hi all, Thanks to you all I've been improving in VBA so thanks again and great this forums exist. Now I have a doubt and I'm not sure how to do it, I want to write a txt file with the information of some cells separating them with commas. I have already use the worksheets.saveas function, the text file is generated correctly but I llike to see if there is any other option, maybe like the open function in order to write only the txt file. Do anyone have any idea for doing this? Thanks again |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for write a txt file
Hi,
You aren't clear about what you want to write but you can create a text file like this Sub write_Texts() Dim SomeName As String SomeName = "MyTextFile" saveDir = "C:\" 'Change to suit targetfile = saveDir & SomeName & ".txt" Open targetfile For Output As #1 Print #1, Range("A1").Text Close #1 End Sub Mike "japfvg" wrote: Hi all, Thanks to you all I've been improving in VBA so thanks again and great this forums exist. Now I have a doubt and I'm not sure how to do it, I want to write a txt file with the information of some cells separating them with commas. I have already use the worksheets.saveas function, the text file is generated correctly but I llike to see if there is any other option, maybe like the open function in order to write only the txt file. Do anyone have any idea for doing this? Thanks again |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for write a txt file
instead of this Print #1, Range("A1").Text which is quiet correct, you could do this: for each cell in Selection | Range("A1:H10") Print #1, cell.Text next "Mike H" wrote: Hi, You aren't clear about what you want to write but you can create a text file like this Sub write_Texts() Dim SomeName As String SomeName = "MyTextFile" saveDir = "C:\" 'Change to suit targetfile = saveDir & SomeName & ".txt" Open targetfile For Output As #1 Print #1, Range("A1").Text Close #1 End Sub Mike "japfvg" wrote: Hi all, Thanks to you all I've been improving in VBA so thanks again and great this forums exist. Now I have a doubt and I'm not sure how to do it, I want to write a txt file with the information of some cells separating them with commas. I have already use the worksheets.saveas function, the text file is generated correctly but I llike to see if there is any other option, maybe like the open function in order to write only the txt file. Do anyone have any idea for doing this? Thanks again |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for write a txt file
I know and would have been more specific had the OP been more specific
Mike "Patrick Molloy" wrote: instead of this Print #1, Range("A1").Text which is quiet correct, you could do this: for each cell in Selection | Range("A1:H10") Print #1, cell.Text next "Mike H" wrote: Hi, You aren't clear about what you want to write but you can create a text file like this Sub write_Texts() Dim SomeName As String SomeName = "MyTextFile" saveDir = "C:\" 'Change to suit targetfile = saveDir & SomeName & ".txt" Open targetfile For Output As #1 Print #1, Range("A1").Text Close #1 End Sub Mike "japfvg" wrote: Hi all, Thanks to you all I've been improving in VBA so thanks again and great this forums exist. Now I have a doubt and I'm not sure how to do it, I want to write a txt file with the information of some cells separating them with commas. I have already use the worksheets.saveas function, the text file is generated correctly but I llike to see if there is any other option, maybe like the open function in order to write only the txt file. Do anyone have any idea for doing this? Thanks again |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for write a txt file
Hi, this should give you an idea of the basics:
Sub demo() Dim fs As Object Dim a As Object Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.createtextfile("C:\demo.txt", True) a.writeline ("line1, blah blah blah") a.writeline ("line2, blah blah blah blah") a.Close End Sub It creates a 2 line text file in root C etc. "japfvg" wrote: Hi all, Thanks to you all I've been improving in VBA so thanks again and great this forums exist. Now I have a doubt and I'm not sure how to do it, I want to write a txt file with the information of some cells separating them with commas. I have already use the worksheets.saveas function, the text file is generated correctly but I llike to see if there is any other option, maybe like the open function in order to write only the txt file. Do anyone have any idea for doing this? Thanks again |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Saving a copy of excel file in macro but have it auto write | Excel Worksheet Functions | |||
Would like Macro example to write out a range of cells to a file | Excel Programming | |||
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? | Excel Worksheet Functions | |||
How to write a macro to open a file read-only? | Excel Programming | |||
How do I write an Excel macro to open a file using the CommonDial. | Excel Programming |