Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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" wrote in message ... 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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 *** |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
excel - create a macro to use cell text as part of a file name | New Users to Excel | |||
How to create a UTF-8 text file from excel VBA | Excel Discussion (Misc queries) | |||
Can I use Excel to create this text file? | Excel Worksheet Functions | |||
How to create text file from selected excel data | Excel Programming | |||
Create and write a simple text file in Excel/VBA | Excel Programming |