Create and write a simple text file in Excel/VBA

T

Thomas Wieser

Hi,

what is the easiest way to create a new text file, write one string into
the file and close it afterwards?


Regards, Thomas
 
F

Frank Kabel

Hi Thomas
have a look at the Write method in the VBA help (included an example
for this)
 
J

JWolf

Dim F1 As Integer
F1 = FreeFile
Open "fullpathname\filename.txt" For Output As F1
Print #F1, "Test line" 'Prints: Test Line
Print #F1, yourvariable 'Prints: the value of your variable
Print #F1, "The vaue of yourvariable is: " & yourvariable 'Prints: the
concatation of "quoted" and yourvariable
Close #F1
F1 = 0
 
B

Bob Phillips

Hi Thomas,

From Help

FileNumber = FreeFile
Open "C:\My Documents\TEST10" For Output As #FileNumber
Write #FileNumber, "This is a sample."
Close #FileNumber

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top