Change this to only run in the current sheet?

samilynn

Board Regular
Joined
Jun 24, 2003
Messages
195
Office Version
  1. 2016
Platform
  1. Windows
This is my code to do print options so I don't have to set them every time, but it runs in all the tabs. I'd like it to run in only the active tab.

Thank you!

Sammy


Option Explicit

Public Sub Print_Portrait()
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each ws In ActiveWorkbook.Sheets
With ws
With .PageSetup
.Orientation = xlPortrait
.PrintGridlines = True
.CenterFooter = "Page &P of &N"
.PrintTitleRows = "$1:$1"
.LeftMargin = Application.InchesToPoints(0)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0.41)
.BottomMargin = Application.InchesToPoints(0.41)
.HeaderMargin = Application.InchesToPoints(0.15)
.FooterMargin = Application.InchesToPoints(0.15)
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
End With
End With
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 
Hi, you could try like this.

VBA Code:
Option Explicit

Public Sub Print_Portrait()
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With ActiveWorkbook.ActiveSheet
    With .PageSetup
        .Orientation = xlPortrait
        .PrintGridlines = True
        .CenterFooter = "Page &P of &N"
        .PrintTitleRows = "$1:$1"
        .LeftMargin = Application.InchesToPoints(0)
        .RightMargin = Application.InchesToPoints(0)
        .TopMargin = Application.InchesToPoints(0.41)
        .BottomMargin = Application.InchesToPoints(0.41)
        .HeaderMargin = Application.InchesToPoints(0.15)
        .FooterMargin = Application.InchesToPoints(0.15)
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = False
    End With
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Hi, you could try like this.

VBA Code:
Option Explicit

Public Sub Print_Portrait()
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With ActiveWorkbook.ActiveSheet
    With .PageSetup
        .Orientation = xlPortrait
        .PrintGridlines = True
        .CenterFooter = "Page &P of &N"
        .PrintTitleRows = "$1:$1"
        .LeftMargin = Application.InchesToPoints(0)
        .RightMargin = Application.InchesToPoints(0)
        .TopMargin = Application.InchesToPoints(0.41)
        .BottomMargin = Application.InchesToPoints(0.41)
        .HeaderMargin = Application.InchesToPoints(0.15)
        .FooterMargin = Application.InchesToPoints(0.15)
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = False
    End With
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Thank you!!!!
 
Upvote 0

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