Excel VBA: Macro hangs after opening a document when run via shortcut key, but runs perfectly from VB editor

后端 未结 1 569
南笙
南笙 2020-12-21 12:56

I ran into a strange problem, I decided to assign a keyboard shortcut Ctrl + Shift + P on one of my routine in VBA. This routine is suppose to open an existing

相关标签:
1条回答
  • 2020-12-21 13:37

    Apparently, after multiples google search about that particular problems, it seems that

    Application.Workbooks.Open(yourPath)
    

    mixed with the Shift keyboard key in your shortcut is the problem. More precisely from this guy if you look at the last answer:

    The shift key makes a vb script stop at any Open statement.

    So you have two solutions

    1. Remove the Shift key from your shortcut and choose another one

    2. Instead of using .Open, you could use .Add which will do the same job, but the code won't hang. So if you do Application.Workbooks.Add(yourPath) it should behave properly.

    It is funny though, that both Open and Add have the exact same behavior when you look at the screen while running the Macro.

    Edit: I couldn't find any official link referring to that bug.

    0 讨论(0)
提交回复
热议问题