Home » excel » c# – Maximum String Length of PrintArea in Excel

c# – Maximum String Length of PrintArea in Excel

Posted by: admin March 9, 2020 Leave a comment

Questions:

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.

How to&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