问题
I need to write data from a macro to a text file. I am using the below code:
VAR_ABC = "Deployment1.txt"
Dim FlName As String
filesize = FreeFile()
Open FlName For Output As #filesize
Write #filesize, "Hello World!"
Write #filesize, "" & VAR_ABC;
Close #filesize
I have below questions:
- The output in my file contains double quotes i.e. "Hello World" "Deployment1.sh" How to get rid of these double quotes in my text file?
Is there a way to write multiple lines in a better way(with new line character) than using Write again and again?
If I am to use variables, is it mandatory to use them like: "" & VarName. Is it not possible to have only VarName in Write Command.
Thanks in Advance!
回答1:
Replace Write
with Print
.
Sub test()
VAR_ABC = "Deployment1.txt"
Dim FlName As String
filesize = FreeFile()
Open "C:\Temp\Hello.txt" For Output As #filesize
Print #filesize, "Hello World!"
Print #filesize, VAR_ABC;
Close #filesize
End Sub
来源:https://stackoverflow.com/questions/38314900/writing-variable-to-a-file-using-macro