简体   繁体   English

连接和评估的VB语法错误

[英]VB syntax error for concatenate and evaluate

I am trying to write a VB script that concatenates data together into a url string and then I want it to copy down into all the rows for that column. 我正在尝试编写一个VB脚本,它将数据连接在一起成为一个url字符串,然后希望将其复制到该列的所有行中。 I've got the fill down code working okay but when I try to add the concatenate I keep getting a syntax error so I'm not sure what I'm doing wrong. 我已经填写好代码,但是当我尝试添加连接时,我不断收到语法错误,所以我不确定自己在做什么错。 I have tried two versions and they both give me syntax errors on the final line of script (right side): 我尝试了两个版本,它们都在脚本的最后一行(右侧)给了我语法错误:

Script Version 1: 脚本版本1:

Sub SetSurveyLink()

' SetSurveyLink Macro

Dim lngLastRow As Long
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("C3:C" & lngLastRow).Value = EVALUATE("https://domainname.com/survey/?PartName=" & 'Client List'!B1 & "&ClientID="&B2)
End Sub

Script Version 2: 脚本版本2:

Sub SetSurveyLink()

' SetSurveyLink Macro

Dim lngLastRow As Long

lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("C3:C" & lngLastRow).Value = CONCATENATE("https://domainname.com/survey/?PartName=",'Client List'!B1,"&ClientID=",B2)

End Sub

The 'concatenate' string gives me the correct value when used in a cell (ie not as part of a script) but I just can't get it to work in the script. 当在单元格中使用时,“连接”字符串为我提供了正确的值(即,不是作为脚本的一部分),但我只是无法使其在脚本中正常工作。 See anything that I'm missing in my syntax? 看到语法中缺少的内容吗?

THANK YOU! 谢谢!

Any double-quote marks within a string need to be escaped to be double double-quote marks so, if 字符串中的任何双引号都需要转义为双双引号,因此,如果

"https://domainname.com/survey/?PartName=" & 'Client List'!B1 & "&ClientID="&B2

worked within Excel, it becomes 在Excel中工作,它变成

""https://domainname.com/survey/?PartName="" & 'Client List'!B1 & ""&ClientID=""&B2

and then you need to enclose that within double-quote marks to make it a string literal within VBA, ie 然后您需要将其括在双引号中,以使其成为VBA中的字符串文字,即

"""https://domainname.com/survey/?PartName="" & 'Client List'!B1 & ""&ClientID=""&B2"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM