增加字符串VBA的允许内存

时间:2013-10-15 12:17:12

标签: string memory excel-vba vba excel

所以我有一些代码可以对API的一些输出进行排序,并将信息提取到电子表格中。问题是我可以设置一些字符串变量的最大字符数似乎是26513个字符(使用debug.print Len(my-overized-string)找到。现在Excel 2010中有一种方法可以扩展一个字符串的数据量可以举行吗?我理想情况下需要我的字符串至少保存3,500,000个字符。这可能还是我应该以不同的方式处理这个问题?

我得到的错误信息是下标超出范围,sParagraph =段落(i)在点击调试后突出显示。

感谢您的帮助! 贾斯汀

Dim URL As String: URL = "someAPIurlputhere"
Dim Http As New WinHttpRequest
    Http.Open "GET", URL, False
    Http.Send
Dim Resp As String: Resp = Http.ResponseText
Dim Paragraph As Variant
    Debug.Print Len(Resp)
    For i = 1 To 365
        Paragraph = Split(Resp, "date")
        ActiveCell.Offset(1, 0).Activate
        ActiveCell.Range("A1:E1").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Dim sParagraph As String: sParagraph = Paragraph(i)
        Dim Lines As Variant: Lines = Split(sParagraph, ",")
        ActiveCell.Offset(0, 1).FormulaR1C1 = Lines(0)
        ActiveCell.Offset(0, 2).FormulaR1C1 = Lines(9)
        ActiveCell.Offset(0, 3).FormulaR1C1 = Lines(27)
        ActiveCell.Offset(0, 4).FormulaR1C1 = Lines(29)
        Erase Paragraph
    Next i

1 个答案:

答案 0 :(得分:2)

您确定26513 characters我能够创建一个98,333,767长度的字符串,其长度比您94,833,767的{​​{1}}长{。}}。

3,500,000

参见此示例

98,333,767 - 3,500,000 = 94,833,767

正如您所看到的,我们得到一个Sub Sample() Dim s As String Dim i As Long '~~> This will create a string of 32767 in length s = Application.WorksheetFunction.Rept("a", 32767) '~~> Adding it in a loop 3000 times to check what length we get For i = 1 To 3000 s = s & Application.WorksheetFunction.Rept("a", 32767) Next i '~~> 98,333,767 Debug.Print Len(s) End Sub 长度的字符串。长度如预期

98,333,767

如果我的记忆正确,那么可变长度字符串最多可包含32767 + (32767 X 3000) = 98333767 个字符。固定长度的字符串最多可包含大约2 billion (2^31)个字符。

从评论中跟进

您正在对值64K (2^16)进行硬编码,并且阵列中没有必要包含那么多项。使用For i = 1 To 365lbound循环遍历数组。

另外,请不要使用Activecell / select等INTERESTING READ

尝试此代码(未测试

ubound