我的代码的单元格 C18 是文件路径
C:\blahblahblah\yay.db
我想写一个txt文件,所以第一行是:
uil_file_new.go( "C:\blahblahblah\yay.db","C:\blahblahblah\yay.db")
我尝试过以下方法:
Dim template As String
template = Range("C18").Value
Open (ThisWorkbook.Path & "\" & "test.txt") For Output Access Write Shared as #1
Print #1, "uil_file_new.go( " & template & "," & template & ")"
Close #1
这给出了
uil_file_new.go( C:\blahblahblah\yay.db ,C:\blahblahblah\yay.db)
我需要 txt 文件在文件路径周围包含“”。有没有办法将变量传递到 txt 文件,但变量包含的内容周围有“”?
我尝试过 Write #1, 命令,但它只是输入"template",这不是我想要的。
它不会让我写单个“,例如这样就可以了:
Write #1, "
Print #1, template
Write #1, "
但它总是将其纠正为
Write #1, ""
最佳答案
要打印 "
将它们加倍到 ""
所以;
Print #1, "uil_file_new.go(""" & template & """,""" & template & """)"
关于VBA打印和写入命令混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9601463/