DLL file not found when invoking function from Excel/VBA

Chris Grossman 25 Reputation points
2025-06-29T01:41:47.34+00:00

I'm running Windows 11 with 64-bit MS/Office 2021. I have a very large (>25KSLOC) Excel/VBA application with a helper DLL written in C and compiled by Visual Studio 2022. The last time I used the app was May 4, 2025, and it worked perfectly. Today, June 28, it won't run. When it gets to the first invocation of a DLL function, it gets the all-too-familiar "File Not Found" VBA error message. But nothing has changed since May 4. The DLL file is unchanged and is in exactly the same place it's always been, and its only dependency (a known cause of the File Not Found error) is Kernel32.dll, which my W11 system most definitely has. And the exact same glitch occurs on my W10 box running 32-bit Excel 2016: ran fine 2 months ago and now crashes with 'File Not Found'. Any ideas how I can determine what's causing the error today when it wasn't happening 2 months ago? I have noticed there have been a couple large Windows Updates over the last 2 months, on both W11 and W10 boxes. Hopefully Microsoft didn't change something that is now making my code fail.

Developer technologies | Visual Basic for Applications
{count} votes

2 answers

Sort by: Most helpful
  1. Chris Grossman 25 Reputation points
    2025-07-11T01:10:20.08+00:00

    This problem was solved by Ryan, a Microsoft Community Support Specialist, on another thread. Microsoft changed the way VBA can reference a DLL so it no longer uses the current directory. The solution I ended up using was to have the VBA code invoke the SetDefaultDllDirectories and AddDllDirectory Windows API functions. I can provide the specific code snippet if desired.

    You and 1 other person found this answer helpful.

  2. simo-k 57,980 Reputation points Volunteer Moderator
    2025-06-29T09:11:40.96+00:00

    Please check whether the DLL library reference settings are properly configured on the VBA side.


Your answer

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