Run-time error 80040154 , When Replacing string locations on VBA

Alexandre Tavares 1 Reputation point
2023-02-01T14:16:55.16+00:00

Hello I am trying to work on a macro enable word document, this document has a VB associated with it. the main issue is the File path location. the original creator of the document used mapped file locations to pull information from an access database located on the server. however this need to be more flexible and needs to have the mapped drive locations replaced with the actual server path locations. when I attempt to replace the file path it generates error 80040154. I am unaware as to why this is happening.

Here is the code already in the document

DBEngine.SystemDB = "Z:system.mdw"

needed replacement

DBEngine.SystemDB = "\\HDFS01\Enginering\system.mdw"

this give error and will not allow me to create the system.mdw to have a session for the access.

Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Word | For business | Windows
Windows for business | Windows Server | User experience | Other
Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Michael Taylor 60,326 Reputation points
    2023-02-01T15:09:35.6966667+00:00

    Can you please provide us more context? You said it gives an error but it isn't clear what actual error you're getting. It also isn't clear when this macro is supposed to run and whether this is the actual line that is failing or something else. A string assignment shouldn't cause any issues so I suspect it is later.

    I'm also confused by the DBengine reference. In VBA my understanding is this object is for the Access engine but you said you're in word. Can you provide us with what the macro is actually doing?

    You mention an error code that seems to be Class Not Registered. That would seem to indicate you're trying to load a COM object (Access?) but it cannot be found. That would happen if you didn't have Access installed or if you had the access runtime installed but it was the x64 version and you're running Office x86, but I didn't think that was allowed by the installer. I could be wrong though.

    Temporarily map the Z drive to the correct UNC path. Does it work? If so then this eliminates most everything except security permissions and network issues.

    0 comments No comments

  2. Limitless Technology 44,766 Reputation points
    2023-02-02T17:16:24.6833333+00:00

    Hi. Thank you for your question and reaching out. I’d be more than happy to help you with your query.

    When trying to replace string places in VBA code, the run-time error 80040154 may appear. This is typically brought on by improper formatting of the string locations or the absence of a referenced library.

    The string locations must be formatted correctly and all referenced libraries must be installed and current before this can be fixed. Try manually registering the relevant library in Windows by executing the following command in Command Prompt if it doesn't fix the problem:

    regsvr32 <library name>.dll

    You might need to repair and/or reinstall the currently installed version of Microsoft Office if the error still occurs.

    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.

    0 comments No comments

  3. Limitless Technology 44,766 Reputation points
    2023-02-02T17:16:32.43+00:00

    Hi. Thank you for your question and reaching out. I’d be more than happy to help you with your query.

    When trying to replace string places in VBA code, the run-time error 80040154 may appear. This is typically brought on by improper formatting of the string locations or the absence of a referenced library.

    The string locations must be formatted correctly and all referenced libraries must be installed and current before this can be fixed. Try manually registering the relevant library in Windows by executing the following command in Command Prompt if it doesn't fix the problem:

    regsvr32 <library name>.dll

    You might need to repair and/or reinstall the currently installed version of Microsoft Office if the error still occurs.

    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.

    0 comments No comments

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.