Create and write a simple text file in Excel/VBA

  • Thread starter Thread starter Thomas Wieser
  • Start date Start date
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
 
Hi Thomas
have a look at the Write method in the VBA help (included an example
for this)
 
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
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top