在双引号内传递变量

时间:2021-06-15 12:52:02

标签: vba

我正在写一个 VBA 代码,我需要在双引号内传递几个变量。 代码如下

Set newrel = rels.AddWithRoleName("Entity1", "Entity1", 1," attr1,attr1_role; col1, col1_role")

这里,对于 "Entity1",我可以传递变量,因为只有一个值,但是对于最后一个参数 "attr1,attr1_role; col1, col1_role",我需要为这些参数传递 4 个变量。

因为这是在双引号内,所以当我传递变量名时它不会取值。

1 个答案:

答案 0 :(得分:1)

如果你有以下变量

  • attr1
  • attr1_role
  • col1
  • col1_role

并且您想将它们作为像 "attr1,attr1_role; col1, col1_role" 这样的字符串传递,那么您需要使用变量创建一个连接字符串:

attr1 & "," & attr1_role & "; " & col1 & ", " & col1_role

例如:

Dim Parameter4 As String
Parameter4 = attr1 & "," & attr1_role & "; " & col1 & ", " & col1_role

Set newrel = rels.AddWithRoleName(Entity1, Entity1, 1, Parameter4)

确保在您的生产环境中使用比 Parameter4 更有意义的名称