我正在创建一个将公式输入到单元格中的函数。但我继续收到语法错误。我知道这是由于引号。我想知道如何在函数中包含公式的引号而不会导致语法错误。
任何帮助都会感激不尽。
Sub codedump()
Range("A1").Value = "=Dump(GoogleAnalytics("ga:78770227", "ga:visits", "2014-05-28", "2014-06-26", "","", "", "", 500, FALSE, FALSE))"
End Sub
答案 0 :(得分:4)
使用转义
例如,""
给出引号。否则,请使用字符代码
Sub codedump()
Range("A1").Value = "=Dump(GoogleAnalytics(""ga:78770227"", ""ga:visits"", ""2014-05-28"", ""2014-06-26"", """","""", """", """", 500, FALSE, FALSE))"
End Sub
来自http://msdn.microsoft.com/en-us/library/267k4fw5(v=vs.85).aspx
备选方案:
'Escaping
Private Sub InsertQuote()
TextBox1.Text = "She said, ""You deserve a treat!"" "
End Sub
'Character code
Private Sub InsertAscii()
TextBox1.Text = "She said, " & Chr(34) & "You deserve a treat!" & Chr(34)
End Sub
'Defined string
Const quote As String = """"
TextBox1.Text = "She said, " & quote & "You deserve a treat!" & quote
答案 1 :(得分:0)
您需要将引号括在引号中以使它们出现在工作表上。类似的东西:
Range("A1").Value = "=Dump(GoogleAnalytics(""ga:78770227"", ""ga:visits"", ""2014-05-28"", ""2014-06-26"", """","""", """", """", 500, FALSE, FALSE))"
应该这样做。
答案 2 :(得分:0)
使用
Chr(34) & Chr(34)
取代
""
34是“和VBA在构建字符串时将Chr(34)转换为”的ASCII字符代码。