VBA 中的字符串连接
我有这个函数:
Function GetFullNameCSV() As String
GetFullNameCSV = Replace(ThisWorkbook.FullName, ".xlsm", ".txt")
End Function
如果代码看起来像这样硬编码:
Filename:= "C:\directory\filename.txt"
我可以用这个替换它并得到相同的结果:
Filename:= GetFullNameCSV()
问题是它出现在这个字符串的情况下:
Connection:= "TEXT;C:\directory\filename.txt"
我需要使用字符串连接,猜测如下:
Connection:= "\"TEXT;+GetFullNameCSV()+\""
我需要使用什么代码?强>谢谢。
I've got this function:
Function GetFullNameCSV() As String
GetFullNameCSV = Replace(ThisWorkbook.FullName, ".xlsm", ".txt")
End Function
If the code looked like this hard coded:
Filename:= "C:\directory\filename.txt"
I could just replace it with this and get the same result:
Filename:= GetFullNameCSV()
Problem is it appears in the case of this string:
Connection:= "TEXT;C:\directory\filename.txt"
I need to use string concatenation, guessing something like this:
Connection:= "\"TEXT;+GetFullNameCSV()+\""
What the code I need to use? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设所有部分始终用
;
分隔,只需将字符串分成几个部分,然后进行更改,然后再次将其连接在一起。因此,对于您的示例,我认为它会是这样的(请注意,是凭记忆写的,所以可能不完全正确):
Assuming that all the sections are always delimited with a
;
, just split the string into it's parts and then do your changes and then join it together again.So with your sample I think it would be something like (please note, written from memory, so might not be completely correct):