Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending data to Excel 1

Status
Not open for further replies.

TrekBiker

Technical User
Nov 26, 2010
330
0
0
GB

I'm exporting data to an Excel spreadsheet but getting an error setting the PrintArea.

Code:
    With objSht.PageSetup
        .Orientation = xlLandscape
'        .PrintArea = "$A$1:$M$92"
        .PrintArea = .UsedRange.Address
        
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 99
    End With

The commented line .PrintArea = "$A$1:$M$92" works but I want the code to automatically use the spreadsheet range to make it more versatile.
A search says I can use UsedRange but with this line get Error 438, 'Object doesn't support this property or method'

Code:
        .PrintArea = .UsedRange.Address

Any help appreciated.



 
UsedRange is a property of Worksheet object, so either:
[tt].PrintArea = .Parent.UsedRange.Address[/tt]
or
[tt].PrintArea = objSht.UsedRange.Address[/tt]


combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top