none
Unreachable PrintPReview Ribbon RRS feed

  • Question

  • Hello everyone,

    I've got an issue with Excel PrintPreview ribbon when I try to call the method on a slave workbook from my master workbook.

    The different step I've done is :

    1. Activate and select a range in the slave workbook, and then call MyPrintPreview. In this case everything is Ok ; I can reach all the button inside the Ribbon
    2. Activate and select a range in the master workbook, and then call MyPrintPreview. In this case, all the ribbon button is unreachable unless I resize my slave workbook.
    3. When running Step1 and Step2 in a loop, I sometime encounter the error message "PrintPreview method of worksheet class failed" the code stop.  but when I press the "continue" button the method don't failed anuymore ; it seems the activate methods on the salve workbook does not run successfuly.

    Here below is the code is used :

    Public Sub MyPrintPreview(xlwbSlave As Workbook)
    
        
        Dim xlwbMaster As Workbook
        Set xlwbMaster = ThisWorkbook
        
        xlwbSlave.Worksheets(1).Activate
        xlwbSlave.Worksheets(1).PrintPreview
        xlwbMaster.Worksheets(1).Activate
            
    
    end sub

    Thanks for your help

    Thursday, February 15, 2018 9:49 AM

All replies

  • Hi Lau_Beginner,

    You had mentioned that,

    (1) Activate and select a range in the slave workbook, and then call MyPrintPreview. In this case everything is Ok ; I can reach all the button inside the Ribbon.

    -> I try to make a test on my side and find that everything is working correctly and i can use the ribbon.

    (2) Activate and select a range in the master workbook, and then call MyPrintPreview. In this case, all the ribbon button is unreachable unless I resize my slave workbook.

    -> I find that It is working find on my side. You can see my testing result below.

    (3) When running Step1 and Step2 in a loop, I sometime encounter the error message "PrintPreview method of worksheet class failed" the code stop.  but when I press the "continue" button the method don't failed anuymore ; it seems the activate methods on the salve workbook does not run successfully.

    -> Based on your above description, I think that the code should work correctly if it run individually.

    It is possible that , When you execute the code in loop at that time, Excel has any pending operation for last print preview and it trying to execute a code for next record. So in that situation, You can get that error.

    As you said , When error occurs and you press continue button then it works correctly because during that time pending operations get finished and you can execute code successfully.

    So you can verify that all process for last record get finished first and then you can execute code for next record may solve your issue or you can pause your code for some mile seconds to finish any pending execution and then move to next record in loop.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 16, 2018 2:21 AM
    Moderator