|
-
May 31st, 2006, 08:56 PM
#1
Thread Starter
Member
[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
-
May 31st, 2006, 09:58 PM
#2
Fanatic Member
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?
-
Jun 1st, 2006, 07:35 PM
#3
Thread Starter
Member
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
-
Jun 1st, 2006, 07:36 PM
#4
Re: Help creating Text Files using VBA Excel
Just change Write to Print, and it should write to the file without quotes.
-
Jun 1st, 2006, 07:45 PM
#5
Thread Starter
Member
Re: Help creating Text Files using VBA Excel
Problem Solved! Thank You!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|