Runtime error 5 when I try to use shell function in Excel VBA

Jason Liu 0 Reputation points
2025-07-29T03:25:59.19+00:00

User's image

I am trying to execute a python script using shell function in VBA to directly run the cmd prompt. But it always returns Runtime error '5' Invalid procedure call or argument.

At first I thought it might be because the python script is not allowed. Then I create a BAT file to wrap up the cmd prompt and try to execute it in VBA using Shell. It returned the same error.

I can successfully run the python script using the exact same command in cmd window. I can also call Notepad.exe using shell, which I think means that the shell is functioning.

Strange thing is that I can run the exact same code two weeks before successfully. I haven't made any changes to the files and when I try to run the code this Monday, it suddenly wouldn't work.

What will be the problem?

Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel-Vo 1,500 Reputation points Microsoft External Staff Moderator
    2025-07-29T06:10:04.34+00:00

    Dear @Jason Liu,

    Good day to you and thanks for your post in Microsoft Q&A. I'm sorry for the inconvenience you've encountered. To better assist you, could you please provide more details such as:

    • What type of your account do you use? Personal or created by organization - school/company?
    • Would you mind sharing me a screenshot of your issue? Besides that, would you mind giving me a detail of your code?
    • What version do you use?

    Regarding your description, I tried to create a simple VBA to call a python script and have some tips that you can consider:

    Once again, I sincerely apologize for the unpleasant experience. I look forward to your information and if you have any questions, please feel free to reach out to me - I’ll be happy to assist you. Wishing you a wonderful day.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.