Getting around the Max String size in a vba function?

前端 未结 6 1328
北海茫月
北海茫月 2020-11-28 15:57

The max number of characters you can use in string in a vba function is 255. I am trying to run this function

Var1= 1
Var2= 2
.
.
.
Var256 =256

RunMacros=          


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 16:24

    This test shows that the string in VBA can be at least 10^8 characters long. But if you change it to 10^9 you will fail.

    Sub TestForStringLengthVBA()
        Dim text As String
        text = Space(10 ^ 8) & "Hello world"
        Debug.Print Len(text)
        text = Right(text, 5)
        Debug.Print text
    End Sub
    

    So do not be mislead by Intermediate window editor or MsgBox output.

提交回复
热议问题