VBA 打印和写入命令混淆
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9601463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Print and Write command confusion
提问by Oliver Bennett
In cell C18 of my code is the filepath
在我的代码的单元格 C18 中是文件路径
C:\blahblahblah\yay.db
I want to write a txt file so the first line reads:
我想写一个txt文件,所以第一行是:
uil_file_new.go( "C:\blahblahblah\yay.db","C:\blahblahblah\yay.db")
I have tried the following:
我尝试了以下方法:
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
which gives
这使
uil_file_new.go( C:\blahblahblah\yay.db ,C:\blahblahblah\yay.db)
I need the txt file to have the " " around the filepaths. Is there is a way to pass a variable to a txt file but have the " " around what the variable contains?
我需要 txt 文件在文件路径周围有“”。有没有办法将变量传递给 txt 文件,但在变量包含的内容周围加上“”?
I have tried the Write #1, command but it just puts "template", which isn't what I want.
我已经尝试了 Write #1, 命令,但它只是放置了“模板”,这不是我想要的。
It won't let me write single ", for example this would be ok:
它不会让我写单个“,例如这可以:
Write #1, "
Print #1, template
Write #1, "
but it always corrects it to
但它总是将其纠正为
Write #1, ""
采纳答案by Alex K.
To print a "
double them up to ""
so;
将"
它们打印成双倍""
;
Print #1, "uil_file_new.go(""" & template & """,""" & template & """)"