Share via

Python Scripts running from excel in Windows 11

Anonymous
2023-11-20T15:05:44+00:00

I am writing vbas in excel in windows 10 and everything works just fine. But since we are moving to windows 11, we have to make sure those vbas work as well. We want to run specific python file-s from the given macro.

PythonExe = "Path/to/phyton.exe"
PythonScript = """Path/to/python_script.py"""

objShell.Run "cmd.exe /s /c " & PythonExe & " " & PythonScript, windowStyle, waitOnReturn

We get an error that states: suspicious macros, the windows defender blocked running them. It always happen when the vba reaches the above lines.

But if I run the macro row-by-row it somehow does it job.

I assume this is a Windows 11 specific error, because we have been using this code in the past 6 months on Windows 11.

Any help why does it happen?

We tried to add the file location to the truested location, but it gave the same error. File> Options> Trust Center> Trust Center Settings> Trusted Locations
Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-11-22T12:46:03+00:00

    i tried to add them to trusted locations but it still didn't work.

    And sadly I can not disable Windows Defender because this is a work computer and the company policy does not let me do that :(

    Any other solution?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2023-11-22T12:57:55+00:00

    I'd suggest you create a new thread in Stack Overflow which is special channel for handle VBA questions.

    Thank you for your understanding.

    0 comments No comments
  3. Anonymous
    2023-11-20T15:42:31+00:00

    You can try adding the folder containing your Python script to the list of trusted locations in Excel.

    If this doesn't work, you can try disabling Windows Defender temporarily to see if it resolves the issue.

    0 comments No comments