Setting up Printing via a macro

odayand

New Member
Joined
May 27, 2013
Messages
11
Hi All

Can anybody assist?

I am new to macros so I have very little coding knowledge.

I am attempting to set up a printing macro for my workbook which has several sheets.

I have been searching the forums for something that would accomplish this to no avail. I did find this Macro which requires me to highlight the print area and then run it.
Code:
Dim myRange As String
     
Sub Printarea()
myRange = Selection.Address
ActiveSheet.PageSetup.PrintArea = myRange
With ActiveSheet.PageSetup
    .PrintTitleRows = ""
    .PrintTitleColumns = ""
    .LeftMargin = Application.InchesToPoints(0.5)
    .RightMargin = Application.InchesToPoints(0.5)
    .TopMargin = Application.InchesToPoints(0.5)
    .BottomMargin = Application.InchesToPoints(0.5)
    .HeaderMargin = Application.InchesToPoints(0.2)
    .FooterMargin = Application.InchesToPoints(0.2)
    .PaperSize = xlPaperA4
    .Orientation = xlPortrait 'xlLandscape
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Preview:=True 'Print Preview
'ActiveWindow.SelectedSheets.PrintOut Copies:=1 'Printout
End Sub
[\Code]
Is there something that will identify the used cells in each cell, set it as the print area, change the orientation to landscape, adjust the margins to 0.5mm all round shrink the columns to fit on one page wide.

Any assistance will be appreciated

Regards
Derryn
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Is there something that will identify the used cells in each cell, set it as the print area, change the orientation to landscape, adjust the margins to 0.5mm all round shrink the columns to fit on one page wide.

Did you mean the used cells on the sheet?

All of those steps can be recorded to a macro. I suggest the 1st step to record is to clear the print area. Then the used range is the print area by default. All the other steps are on the Page Setup dialog and can be recorded.
 
Upvote 0
Thanks for the reponse

Used the following and it worked

Dim W As Worksheet

For Each W In ActiveWorkbook.Worksheets
With W.PageSetup
.Printarea = W.UsedRange.Address
.PrintTitleRows = ""
.PrintTitleColumns = ""
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.2)
.FooterMargin = Application.InchesToPoints(0.2)
.PaperSize = xlPaperA4
.Orientation = xlPortrait 'xlLandscape
.Zoom = False
.FitToPagesWide = 1
End With
W.PrintOut Copies:=1, Preview:=True 'Print Preview
'W.PrintOut Copies:=1 'Printout
Next W
 
Upvote 0

Forum statistics

Threads
1,217,414
Messages
6,136,494
Members
450,016
Latest member
murarj

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