Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Print area

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
grahammal - 23 Feb 2006 09:16 GMT
If I wanted to set the print area to just print
Sheets("Sheet1").Range("A1":"E9")
rather than the whole sheet, how do I do this from a macro button. I
know that
ActiveSheet.Printout prints the whole sheet,  but I need to set the
print area 1st.
The print area will be variable depending on what I decide to import
into the active sheet.

Signature

grahammal

NickHK - 23 Feb 2006 09:47 GMT
grahammal,
Try:
With ActiveSheet
   .PageSetup.PrintArea = .UsedRange.Address
End With

NickHK

> If I wanted to set the print area to just print
> Sheets("Sheet1").Range("A1":"E9")
[quoted text clipped - 4 lines]
> The print area will be variable depending on what I decide to import
> into the active sheet.
grahammal - 23 Feb 2006 12:35 GMT
Sheets("Sheet1").Range("A4":"A8")

Sub Button1_Click()
With ActiveSheet
PageSetup.PrintArea = .UsedRange.Address
End With
End Sub

What do I need to substitute with what for the above to work?
I assume that either the 'UsedRange' or the 'Address' part has to be
substituted with something for that to work.

Signature

grahammal

GS - 23 Feb 2006 17:37 GMT
.UsedRange is a worksheet property that includes all cells on a sheet that
have data.

.Address is the absolute reference from the first cell in the upper left
corner, to the last cell in the lower right corner, of .UsedRange.

That means everything on the sheet will print!

If you can live with doing what you want manually, then select the cells to
print and specify "Selection" in the print dialog's "Print what" section.
Otherwise, you'll have to define the imported data as a named range and refer
to it in code.

Regards,
GS

> Sheets("Sheet1").Range("A4":"A8")
>
[quoted text clipped - 7 lines]
> I assume that either the 'UsedRange' or the 'Address' part has to be
> substituted with something for that to work.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.