1

そのため、API からの出力を並べ替えて、情報をスプレッドシートに抽出するコードがあります。問題は、文字列変数を設定できる最大文字数が約 26513 文字のように見えることです (debug.print Len(my-oversized-string を使用して検出)。現在、Excel 2010 で文字列のデータ量を拡張する方法があります。保持できますか?理想的には、文字列に少なくとも 3,500,000 文字を保持する必要があります.これは可能ですか、または別の方法でこの問題に取り組む必要がありますか?

表示されるエラー メッセージは範囲外の添え字であり、デバッグをクリックすると sParagraph = Paragraph(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
4

1 に答える 1

2

要件の よりも長い長さ26513 charactersの文字列を作成できましたか?98,333,76794,833,7673,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 365をハードコーディングしているため、配列にそれほど多くの項目が含まれている必要はありません。lboundおよびを使用しuboundて、配列をループします。

また、 Activecell /select などは使用しないでください。

このコードを試してください (未テスト)

Sub Sample()
    Dim URL As String: URL = "someAPIurlputhere"
    Dim Http As New WinHttpRequest
    Dim Resp As String, sParagraph As String
    Dim Paragraph As Variant, Lines As Variant
    Dim i As Long
    Dim ws As Worksheet

    Http.Open "GET", URL, False
    Http.Send

    Resp = Http.ResponseText

    Debug.Print Len(Resp)

    Paragraph = Split(Resp, "date")

    '~~> Change as applicable
    Set ws = ThisWorkbook.Sheets("Sheet1")

    With ws
        '~~> Loop through the array
        For i = LBound(Paragraph) To UBound(Paragraph)
            .Range("A1:E1").Insert Shift:=xlDown, _
            CopyOrigin:=xlFormatFromLeftOrAbove

            sParagraph = Paragraph(i)

            Lines = Split(sParagraph, ",")

            '~~> I haven't changed this part. Please do not
            '~~> use Activecell. Work with actual range.
            '.Range("B1").Formula = Lines(0)
            '.Range("C1").Formula = Lines(9)
            '.Range("D1").Formula = Lines(27)
            '.Range("E1").Formula = Lines(29)

            ActiveCell.Offset(0, 1).Formula = Lines(0)
            ActiveCell.Offset(0, 2).Formula = Lines(9)
            ActiveCell.Offset(0, 3).Formula = Lines(27)
            ActiveCell.Offset(0, 4).Formula = Lines(29)

            Erase Paragraph
        Next i
    End With
End Sub
于 2013-10-15T13:31:57.950 に答える