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 / November 2007

Tip: Looking for answers? Try searching our database.

Using VBA to print a range

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joel - 10 Nov 2007 16:11 GMT
Hi to all out there

Hi I was wondering if there is a way of writting VBA code to print a range
in Excel 2003 with a page title this would all happen from a command button.
I could use a macro but I have always been told that VBA is the better way to
go

Thanks in advance

Joel  
Signature

N/A

Dave Morrison - 10 Nov 2007 16:26 GMT
Range("A3:C9").PrintOut Copies:=1, Collate:=True

Dave
Gary Keramidas - 10 Nov 2007 16:44 GMT
you can sue something like this, just change some of the settings to get what
you want:

Private Sub CommandButton1_Click()
     Dim ws As Worksheet
     Dim rng As Range
     Dim lastrow As Long
     Set ws = Worksheets("Sheet1")
     lastrow = ws.Cells(Rows.Count, "G").End(xlUp).Row
     Application.ScreenUpdating = False
     Set rng = ws.Range("A1:G" & lastrow)

     With ws
           With .PageSetup
                 .Orientation = xlPortrait
                 .FooterMargin = Application.InchesToPoints(0.25)
                 .RightMargin = Application.InchesToPoints(0#)
                 .LeftMargin = Application.InchesToPoints(0#)
                 .TopMargin = Application.InchesToPoints(0.9)
                 .BottomMargin = Application.InchesToPoints(0.45)
                 .PrintArea = rng.Address
                 .HeaderMargin = Application.InchesToPoints(0.25)
                 .CenterHeader = "&B&14Sheet1 Title"
                 .FitToPagesTall = 1
                 .FitToPagesWide = 1
                 .CenterHorizontally = True
           End With
           .PrintPreview
     End With
     Application.ScreenUpdating = True
End Sub
Signature


Gary

> Hi to all out there
>
[quoted text clipped - 6 lines]
>
> Joel
Joel - 10 Nov 2007 17:17 GMT
Thank you very can you please tell me how to print without the colour that is
on the spreadsheet

Joel
Signature

N/A

> you can sue something like this, just change some of the settings to get what
> you want:
[quoted text clipped - 37 lines]
> >
> > Joel
Joel - 10 Nov 2007 17:17 GMT
Thank you very can you please tell me how to print without the colour that is
on the spreadsheet

Joel
Signature

N/A

> you can sue something like this, just change some of the settings to get what
> you want:
[quoted text clipped - 37 lines]
> >
> > Joel
Gord Dibben - 10 Nov 2007 18:54 GMT
Add this line to Gerry's code.

.BlackAndWhite = True

BTW.......Macros are written using VBA so they are the same thing.

Gord Dibben  MS Excel MVP

>Thank you very can you please tell me how to print without the colour that is
>on the spreadsheet
>
>Joel
 
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.