Stop my macro going to Print Preview PLEASE!

oliviar

Board Regular
Joined
Sep 12, 2010
Messages
184
Hi Guys,
My macro, it works SO WELL. Except that I cannibalised parts from all over, and I can't stop it going to Print Preview. I just want it to remain on the view it was on. Because right now, its running sheet 1, going to print preview, I have to close that, then sheet 2, print preview, close that, sheet 3... etc etc.

Please help:

Code:
Private Sub Workbook_Open()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
Sheets(wsheet.Name).Select
Range("e3").Value = Sheets(1).Range("e3").Value + 1
ActiveWorkbook.Save
    Dim r As Range
    Set r = Worksheets("Sheet1").Range("e3")
    With ActiveSheet.PageSetup
        .LeftHeader = r
    End With
    ActiveWindow.SelectedSheets.PrintPreview
    Next wsheet
    
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Just remove the PrintPreview line from within the loop.

If you do actually want to preview you could add it, or similar after the loop.
Code:
ThisWorkbook.Worksheets(Array("Sheet2", "Sheet3")).PrintPreview
 
Upvote 0
No that doesn't work. It gives me an error saying 'next without for' or something like that:

This is what I end up with after I delete that line:
Code:
Private Sub Workbook_Open()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
Sheets(wsheet.Name).Select
Range("e3").Value = Sheets(1).Range("e3").Value + 1
ActiveWorkbook.Save
    Dim r As Range
    Set r = Worksheets("Sheet1").Range("e3")
    With ActiveSheet.PageSetup
        .LeftHeader = r
    Next wsheet
    
End Sub
 
Upvote 0
You removed the 'End With' statement. Why?
 
Upvote 0

Forum statistics

Threads
1,214,566
Messages
6,120,266
Members
448,953
Latest member
Dutchie_1

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