Consulting

Results 1 to 5 of 5

Thread: Excel 2016 Buttons in Print Preview Disabled

  1. #1

    Excel 2016 Buttons in Print Preview Disabled

    Hello,
    I have troubles with Excel 2016. I have a button on a form which hides the form then print previews a sheet then shows the form again.



    Sub CommandButton1_Click()
    me.hide
    sheet1.printpreview
    me.show
    End Sub

    However, all the buttons in print preview are disabled! So I can't print the sheet or anything the only thing I can do is close the print preview down by clicking the x in the top right corner. This only happens when I load the form when the workbook is opended eg

    Sub Workbook_Open()
    userform1.show
    End Sub

    If I remove this code and manually run the userform after I have opened the workbook it works perfect. All the buttons are enabled and clickable. It also works if I put a button on a sheet and have it show the userform when clicked. But I need to load the form automatically when the workbook is opened not by manually running it or clicking a button to open it etc.


    Anyone have suggestion to solve this issue?

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,768
    Location
    Try not loading it directly from the Open event. Create a routine that just shows the form, then use OnTime in the Workbook_Open event to schedule that - e.g.

    private sub workbook_open()
    application.ontime now(), "myShowForm"
    end sub
    Be as you wish to seem

  3. #3
    This worked okay for me:

    Private Sub btnShowPreview_Click()
    
    
        Me.Hide
        DoEvents
        ThisWorkbook.Sheets("Sheet1").PrintPreview True   ' allow user to edit the parameters
        DoEvents
        Me.Show False  ' don't make the form modal which allows other items to be interacted with
        
    End Sub
    Private Sub Workbook_Open()
        UserForm1.Show False ' don't make the form modal which allows other items to be interacted with
    End Sub
    edit: tested in Office 2010 and Office 2021 (I don't have 2016)
    Attached Images Attached Images

  4. #4
    Try not loading it directly from the Open event. Create a routine that just shows the form, then use OnTime in the Workbook_Open event to schedule that - e.g.

    private sub workbook_open()
    application.ontime now(), "myShowForm"
    end sub
    Thanks for your answer. I got it

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,771
    Location
    I usually avoid OnTime if I can

    Just .Show the Userform using vbModeLess

    Option Explicit
    
    
    Sub Workbook_Open()
        UserForm1.Show vbModeless
    End Sub
    
    
    
    Private Sub CommandButton1_Click()
        Me.Hide
        Sheet1.PrintPreview
        Me.Show
    End Sub
    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •