word macro ends with error53 kernel32 not found

von Fintel, Jörg 0 Reputation points
2026-10-15T09:30:03.1333333+00:00

running a word macro using

Private Declare Function SetEnv Lib "kernel32" _

    Alias "SetEnvironmentVariableA" (ByVal chName As String, _

       ByVal chValue As String) _

    As Long

and

ret = SetEnv("PATH", chPath$)

ends with error 53: file not found: kernel64

Microsoft 365 and Office | Word | For business | Windows
0 comments No comments

2 answers

Sort by: Most helpful
  1. Senthil kumar 2,585 Reputation points
    2026-10-15T10:41:08.3833333+00:00

    Hi @von Fintel, Jörg

    As per your error message. root cause for compatibility issue. so, first check your word as 64 bit version.

    how to check your version File -> account -> about word.

    suppose your version is not an issue then try below code in vba.

    Dim ret As Long
    ret = SetEnvironmentVariable("PATH", chPath)
    If ret = 0 Then
        MsgBox "Failed to set PATH"
    End If
    
    
    

    Thanks.

    Was this answer helpful?

    0 comments No comments

  2. Liora 2,595 Reputation points Independent Advisor
    2026-10-15T09:53:15.1033333+00:00

    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. 

    Was this answer helpful?


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.