Excel中PrintArea的最大字符串长度

Joe*_*Net 6 c# excel vba excel-vba

Excel 2003和2010中PrintArea的最大字符串长度是多少?

我的PrintArea字符串长度为677.

这在Excel 2003中引发了错误,但在2010年没有,因此我想知道两个版本以及2007中的最大字符串长度是多少.

Ste*_*bob 4

2003 年和 2007 年的限制为 255 个字符。

我没有 2010 的副本来测试,但您可以使用此 VBA 代码轻松测试它。只需运行宏,在它崩溃后,转到“调试”,然后检查 i 的值。比该值少 1 的就是最大字符串长度。

Sub PrintRangeTest()

    Dim i As Integer
    Dim j As Integer
    Dim newName As String
    newName = ""
    Dim rng As Range

    For i = 1 To 100000 //some arbitrarily large number
        newName = ""
        For j = 1 To i
            newName = newName & "a"
        Next

        Set rng = ActiveSheet.Range(Cells(1, 1), Cells(i, i))
        rng.Name = newName

        ActiveSheet.PageSetup.PrintArea = rng
    Next

End Sub
Run Code Online (Sandbox Code Playgroud)