Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum String Length of PrintArea in Excel

Tags:

c#

excel

vba

What is the maximum string length of PrintArea in Excel 2003 and 2010?

I have a PrintArea string length of 677.

This throws an error in Excel 2003, but not in 2010, so I'd like to know what the maximum string length is in both versions as well as 2007.

like image 484
Joe.Net Avatar asked May 16 '11 08:05

Joe.Net


1 Answers

The limit in 2003 and 2007 is 255 characters.

I don't have a copy of 2010 to test, but you can use this VBA code to test it easily. Just run the macro and after it crashes, go to Debug, and check the value of i. One less than that will be the maximum string length.

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
like image 141
Stewbob Avatar answered Sep 28 '22 10:09

Stewbob