[RESOLVED] Help creating Text Files using VBA Excel
I am trying to figure out a way to create a simple text file from excel (using VBA). The code below comes close but with a hitch. The stext string seems to need the quotations which presents a problem.
I would like an example of VBA code that can create a text file and pass a string without quotations.
Dim sFile As String
Dim sText As String
Dim iFileNum As Integer
sFile = "C:\(path)\Textfile.txt"
sText = "myString"
iFileNum = FreeFile
Open sFile For Output As iFileNum
Write #iFileNum, sText
Close #iFileNum
Re: Help creating Text Files using VBA Excel
Hmmm, I think you need to say more. Welcome to the forums, by the way. If the value of a text variable is assigned within VBA, it has to be surrounded by quotes. Otherwise it will be interpreted as the name of a variable or cause an error. Perhaps you can explain why it poses a problem and explain a little more what you are trying to do?
Re: Help creating Text Files using VBA Excel
Hey, Thanks for the explaination. The reason the quotations pose a problem is because the quotations themselves get passed to the text file along with the string.
What I am trying to do is create a text file with specified text (syntax for a console application) from Excel.
So if anyone could give me an example of creating a text file (Hello World maybe?)using VBA from Excel, I would appreciate it greatly. i dont really care about the code i provided (whether it gets used or not), I just need a method to this end. Thanks
Re: Help creating Text Files using VBA Excel
Just change Write to Print, and it should write to the file without quotes.
Re: Help creating Text Files using VBA Excel
Problem Solved! Thank You!