Printing and VBA

longytravel

Board Regular
Joined
Aug 2, 2011
Messages
68
Morning,

I have the following code

Code:
Private Sub CommandButton4_Click()
ActiveSheet.PageSetup.Orientation = xlLandscape
Range("B2:J30").PrintOut
End Sub

Columns H, I and J are printed on a second sheet

What code do i need to get in so that excel fits all columns to into the width of the page when printed?

As ever any help greatfullyl recieved!

Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Code:
Private Sub CommandButton4_Click()
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.FitToPagesWide = 1
End With
Range("B2:J30").PrintOut
End Sub
 
Upvote 0
adapt as needed :)

Code:
[COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Sub[/COLOR] cusPrintArea() 
     
    [COLOR=#0000ff]Dim[/COLOR] myRange [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR] 
     
    myRange = "B2:J30"
    ActiveSheet.PageSetup.PrintArea = myRange 
     
    [COLOR=#0000ff]On Error Goto[/COLOR] 1 
    1: Exit [COLOR=#0000ff]Sub[/COLOR] 
     
    [COLOR=#0000ff]With[/COLOR] ActiveSheet.PageSetup 
        .LeftHeader = "" 
        .CenterHeader = "" 
        .RightHeader = "" 
        .LeftFooter = "" 
        .CenterFooter = "" 
        .RightFooter = "" 
        .LeftMargin = Application.InchesToPoints(0.5) 
        .RightMargin = Application.InchesToPoints(0.5) 
        .TopMargin = Application.InchesToPoints(0.5) 
        .BottomMargin = Application.InchesToPoints(0.5) 
        .HeaderMargin = Application.InchesToPoints(0.5) 
        .FooterMargin = Application.InchesToPoints(0.5) 
        .PrintHeadings = [COLOR=#0000ff]False[/COLOR] 
        .PrintGridlines = [COLOR=#0000ff]False[/COLOR] 
        .PrintComments = xlPrintNoComments 
        .PrintQuality = 600 
        .CenterHorizontally = [COLOR=#0000ff]False[/COLOR] 
        .CenterVertically = [COLOR=#0000ff]False[/COLOR] 
        .Orientation = xlLandscape 
        .Draft = [COLOR=#0000ff]False[/COLOR] 
        .PaperSize = xlPaperLetter 
        .FirstPageNumber = xlAutomatic 
        .Order = xlDownThenOver 
        .BlackAndWhite = [COLOR=#0000ff]False[/COLOR] 
        .Zoom = [COLOR=#0000ff]False[/COLOR] 
        .FitToPagesWide = 1 
        .FitToPagesTall = 1 
        .PrintErrors = xlPrintErrorsDisplayed 
    [COLOR=#0000ff]End With[/COLOR] 
     
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=[COLOR=#0000ff]True[/COLOR] 
     
[COLOR=#0000ff]End Sub[/COLOR]

enjoy
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,275
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top