Dear @von Fintel, Jörg,
I hope you’re having a good day
Thank you for providing the code snippet.
One detail stands out immediately: the declaration shown in the question references kernel32, but the error message reports: Error 53: File not found: kernel64
Normally, the Windows API function SetEnvironmentVariableA is provided by kernel32.dll, not by a file named kernel64.dll. This suggests that the error may be originating from another declaration or compatibility block elsewhere in the VBA project rather than from the specific line you posted.
A good starting point would be to search the entire VBA project for the text "kernel64". If any declaration, module, or conditional compilation block references kernel64, that would explain the Error 53 message.
Another possibility is that the macro was originally written for an older version of Office and is now running in a newer 64-bit Office environment. In those situations, API declarations sometimes need to be updated for 64-bit compatibility, and VBA may be loading a different declaration than expected.
It would also be helpful to know:
- Which version of Word you are using.
- Whether Word is installed as 32-bit or 64-bit.
- Whether the error occurs exactly when
SetEnv is called, or earlier in the execution.
- Whether a search of the VBA project finds any reference to kernel64.
Based on the information available so far, the most likely explanation is that another part of the VBA project is attempting to load kernel64 instead of kernel32, or that a legacy API declaration is not fully compatible with the current Office installation.
Please understand that our initial response does not always resolve the issue immediately. However, with your help and more detailed information, we can work together to find a solution.
Looking forward to hearing back from you with any updates or additional details.
Warm regards,
If the answer is helpful, please select "Yes, accept answer". If you have any questions or new updates, please feel free to comment below.