Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default 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
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
Saving a copy of excel file in macro but have it auto write pano Excel Worksheet Functions 4 March 27th 07 11:54 PM
Would like Macro example to write out a range of cells to a file Bryan Excel Programming 1 February 23rd 06 09:08 PM
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? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
How to write a macro to open a file read-only? Mark Seger Excel Programming 20 June 5th 05 05:31 PM
How do I write an Excel macro to open a file using the CommonDial. Lynn Excel Programming 2 March 30th 05 02:31 PM


All times are GMT +1. The time now is 03:21 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"