none
Excel macro to open 2 workbooks RRS feed

  • Question

  • I have created a macro to open 2 workbooks.

    When I run the macro using the keyboard shortcut only the first file is opened.

    When I run the macro from the Macro dialog box it works. 

    Perhaps this is a bug?


    Saturday, March 17, 2018 8:21 AM

Answers

  • Hello nivlektech,

    I could reproduce your issue.

    It seems that the Shift in shortcuts caused this issue. As we know, opening excel with pressing Shift  key will prevent code to run.

    So I think in your case, Ctrl+Shift+Q run the macro and Shift works to prevent the code running while opening first file.

    You could use Ctrl+Q as shortcut to run to macro.

    Besides, you could also modify code like below to clear up effect due to Shift.

    Sub Test()
    DoEvents
    Workbooks.Open Filename:="C:\Users\v-guaxu\Desktop\TestFolder\File1.xlsx"
    Workbooks.Open Filename:="C:\Users\v-guaxu\Desktop\TestFolder\File2.xlsx"
    End Sub

    Best Regards,

    Terry


    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.

    • Marked as answer by nivlektech Monday, March 19, 2018 8:12 PM
    Monday, March 19, 2018 7:08 AM

All replies

  • Hi,

    This is the forum to discuss questions and feedback for Microsoft Excel features, I'll move your question to the MSDN forum for Excel

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Emi


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, March 19, 2018 3:26 AM
  • Hello nivlektech,

    I could reproduce your issue.

    It seems that the Shift in shortcuts caused this issue. As we know, opening excel with pressing Shift  key will prevent code to run.

    So I think in your case, Ctrl+Shift+Q run the macro and Shift works to prevent the code running while opening first file.

    You could use Ctrl+Q as shortcut to run to macro.

    Besides, you could also modify code like below to clear up effect due to Shift.

    Sub Test()
    DoEvents
    Workbooks.Open Filename:="C:\Users\v-guaxu\Desktop\TestFolder\File1.xlsx"
    Workbooks.Open Filename:="C:\Users\v-guaxu\Desktop\TestFolder\File2.xlsx"
    End Sub

    Best Regards,

    Terry


    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.

    • Marked as answer by nivlektech Monday, March 19, 2018 8:12 PM
    Monday, March 19, 2018 7:08 AM
  • Thanks Terry, 

    I have added the 'DoEvents' line and that has worked nicely.

    Monday, March 19, 2018 8:12 PM