Send userform behind Print Preview page

Peter Rattigan

Board Regular
Joined
Oct 18, 2004
Messages
77
I wish to run this macro from a command button on a userform. When it runs it opens the correct sheet for a print preview but it opens it behind the userform and locks up the code which is still running but can't be stopped.
What would I need to add to this code to bring the print preview to the front and leave the userform available once the print preview is closed down? Any help appreciated thanks.
Code:
Sub PrintSC1()
'
' PrintSC1 Macro


'
    Application.ScreenUpdating = False
    Sheets("Scenario 1").Visible = True
    MsgBox "You have selected the Preview for Scenario 1. If you are happy with it select PRINT. If you wish to make changes select CLOSE.", , "Scenario 1 Preview"
    Sheets("Scenario 1").Select
    ActiveWindow.SelectedSheets.PrintPreview
    Sheets("Scenario 1").Visible = False
    Sheets("frontpage").Select
    Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
This works Ok for me :-
Code:
Private Sub CommandButton1_Click()
    Me.Hide
    ActiveSheet.PrintPreview
    Me.Show
End Sub
 
Upvote 0
This worked for me:

Code:
' General module

Sub ShowForm()
    UserForm1.Show vbModeless
End Sub

' UserForm module

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Sheets("Scenario 1").Visible = True
    MsgBox "You have selected the Preview for Scenario 1. If you are happy with it select PRINT. If you wish to make changes select CLOSE.", , "Scenario 1 Preview"
    Sheets("Scenario 1").Select
    Me.Hide
    ActiveWindow.SelectedSheets.PrintPreview
    Sheets("Scenario 1").Visible = False
    Sheets("frontpage").Select
    Application.ScreenUpdating = True
    Me.Show
End Sub

Note that showing a UserForm modelessly requires Excel 2000 or later.
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,245
Members
448,952
Latest member
kjurney

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