Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 91789

Page Setup Tools is Disabled - PrintPreview

$
0
0

I am running a spreadsheet that has a macro. Within this macro there is a Userform. This userform has a button that when pressed opens the print preview of data in a spreadsheet. When I execute the "PrintPreview" method, all buttons the page setup tools are disabled, as can be seen in the image below.

enter image description here

Below is the code I'm running

Private Sub Workbook_Open()
    UserForm1.Show
End Sub

The code below is inside UserForm1

Private Sub CommandButton1_Click()
Dim MySheet As Worksheet

Application.ScreenUpdating = False
Set MySheet = Worksheets("Plan3")

MySheet.Select
MySheet.Range("$A1:$AI166").Select
MySheet.PageSetup.PrintArea = "$A$1:$AI$166"

ActiveWindow.View = xlNormalView
Application.ScreenUpdating = True
Me.Hide
MySheet.PrintPreview
Me.Show
End sub

I couldn't find the reason why the Page Setup Tools buttons is disabled. Can someone help me?

Note 1: This code is inside a userform. The userform is loaded into the Workbook_Open() event.

Note 2: When I open the spreadsheet by double clicking on the file, the userform is loaded automatically. Clicking the CommandButton1 button displays the print preview screen, however the Page Setup Tools buttons is disabled.

If I open the Visual Basic editor and run the Workbook_Open(), clicking the CommandButton1 button shows the print preview screen and the Page Setup Tools buttons are enabled. That is, if the macro runs with the Visual Basic editor open the problem does not happen.

Note 3: This is only happening in the 2007 version of excel.

Note 4: I did a test by opening UserForm1 in "(vbModeless)" mode. In this case the problem did not occur. However in the application I am developing, I need to open the userform in "(vbModal)" mode.


Viewing all articles
Browse latest Browse all 91789

Trending Articles