gpt4 book ai didi

vba - 定义大型VBA字符串的最佳方法-即等效Heredoc吗?

转载 作者:行者123 更新时间:2023-12-03 20:17:16 29 4
gpt4 key购买 nike

如何在VBA中定义大字符串?有没有比下面的代码更好的方法?

Dim largeString as String
largeString = "This is a long block of text that I want to fill " & _
"into a form field. I need to make sure I pay attention " & _
"to spacing and carriage return issues while doing so. " & _
"I also have to use quotes liberally, the concatenation " & _
"operator, and the continuance underscore to make sure " & _
"VBA can parse my code." & vbCr & vbCr & _
"It's kind of a pain in the ass and I wish I could use " & _
"a heredoc instead, letting me copy and paste the block" & _
"of text I need from another source and shove it into " & _
"a string."


编辑:gh,还有25行连续限制吗?缩进和80个字符的宽度非常重要,这只给我足够的空间容纳几个不错的段落。

最佳答案

不,这是最好的。

对于非常长的字符串,可以选择将字符串保存在单独的文件中,或者使用某些应用程序功能。例如,在Word中,您可能希望将字符串存储为文档变量,如隐藏文本或自动图文集。在Excel中,您可能会考虑使用隐藏表来存储长字符串常量。

关于vba - 定义大型VBA字符串的最佳方法-即等效Heredoc吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3671308/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com