Hi, Can we programme excel to create a Text file in the folder using VBA? For example: I want to programme VBA to create a file call Mysave.txt inside one of the folder? Can that be done?? Pls help me... Thanks alot..
Hi, Can we programme excel to create a Text file in the folder using VBA? For example: I want to programme VBA to create a file call Mysave.txt inside one of the folder? Can that be done?? Pls help me... Thanks alot..
Try something like the following:
Dim FName As String
Dim Ndx As Long
FName = "H:\Test\test.txt" '<< CHANGE
Open FName For Output As #1
For Ndx = 1 To 10
Print #1, Ndx
Next Ndx
Close #1
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
"Acube" <Acube.208xny_1134927002.6797@excelforum-nospam.com>
wrote in message
news:Acube.208xny_1134927002.6797@excelforum-nospam.com...
>
> Hi, Can we programme excel to create a Text file in the folder
> using
> VBA? For example: I want to programme VBA to create a file call
> Mysave.txt inside one of the folder? Can that be done?? Pls
> help me...
> Thanks alot..
>
>
> --
> Acube
> ------------------------------------------------------------------------
> Acube's Profile:
> http://www.excelforum.com/member.php...o&userid=29734
> View this thread:
> http://www.excelforum.com/showthread...hreadid=494451
>
If you want to be a little more elegant this will present the typical
windows file dialog box. The user can input a new file name and then
write to the text stream.
Just presenting another option. Notice you have to refence the
Microsoft Scripting Runtime and I typically close the text stream before
exiting the module.
Option Explicit
' Requires Reference to Microsoft Scripting Rntime
Sub Test()
Dim fsoFileSystemObject As FileSystemObject
Dim strFileName As String
Dim tsTextStream As TextStream
Set fsoFileSystemObject = CreateObject("Scripting.FileSystemObject")
strFileName = Application.GetSaveAsFilename()
Set tsTextStream = fsoFileSystemObject.CreateTextFile(strFileName)
tsTextStream.WriteLine "Line 1"
tsTextStream.WriteLine "Line 2"
tsTextStream.WriteLine "Line 3"
tsTextStream.Close
End Sub
*** Sent via Developersdex http://www.developersdex.com ***
Try this
ActiveCell.FormulaR1C1 = Range("A1")
ActiveCell.FormulaR1C1 = Range("A2")
Open "C\text.txt" For Append As #1
Write #1, Range("A1"),1Range("A2")
Close #1
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks