Excel VBA, error message 4198 when computer is offline

Anonymous
2024-05-28T14:43:33+00:00

Hello, I have an Excel document with a macro that opens a word-file. The macro runs fine in online mode and in offline mode when Word-document is stored on USB. I get error message 4198 'Command failed' when computer is offline and Word file is saved on desktop/document folder.

Macro code (red/bold text generate 4198)

Set WordApp = CreateObject("word.Application")

WordApp.Documents.Open FileNameTemplate

Your help is highly valued!

Regards Wilhelm

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
{count} votes

12 answers

Sort by: Most helpful
  1. Anonymous
    2024-05-29T12:22:08+00:00

    Thank you, I have asked my corporate IT team to create a support ticket via Microsoft 365 Admin Center.

    I wish you a great day!

    Regards Wilhelm

    0 comments No comments
  2. Anonymous
    2024-07-01T15:12:07+00:00

    Hi Wilhelm,

    Good day. Hope you are doing well.

    Sharing this information here as it may help others with the same problem.

    Opening files monitored by OneDrive service need to have connectivity to SharePoint Online in order to check if the local version of the file is still the latest.

    We have same problem if we try to launch Word and open a document in a folder being monitored by OneDrive service when in offline mode.

    Example: winword.exe " C:\Users<username>\OneDrive - Contoso\Desktop\Test.docx"

    ![](https://learn-attachment.microsoft.com/api/attachments/49d72f4e-fcbf-41a1-a3d9-286407be8c03?platform=QnA"https://learn-attachment.microsoft.com/api/attachments/17ade46a-95c4-4831-adec-7528244ee7df?platform=QnA" title="filestore.community.support.microsoft.com" rel="ugc nofollow">

    Solution 1

    We don’t get this error if we temporarily pause syncing in OneDrive: How to Pause and Resume sync in OneDrive - Microsoft Support 

    This can be used as a workaround when users don’t have internet connectivity.

    Solution 2

    There’s also another option which consists in adapting the VBA code to handle the runtime error and, if the error occurs, to copy the monitored file from user’s Desktop to the TEMP folder and then open it from that location.

    I’m adding the following VBA script for reference:

        Dim WordApp As Word.Application
    
        Set WordApp = CreateObject("Word.Application")
    
        Filename = "C:\Users\<user>\OneDrive - Contoso\Desktop\test.docx"
    
        On Error GoTo Catch
    
        WordApp.Documents.Open Filename
    
    Continue:
    
        WordApp.Visible = True
    
        'Your code continues here
    
        Set WordApp = Nothing
    
        Exit Sub
    
    Catch:
    
        If Err.Number = 4198 Then 'Command failed - Trying to open a OneDrive monitored file when in offline mode
    
            FileCopy Filename, Environ("TMP") & "\" & "test.docx"
    
            WordApp.Documents.Open Environ("TMP") & "\" & "test.docx"
    
            Resume Continue
    
        Else
    
            MsgBox Err.Description
    
            Set WordApp = Nothing
    
        End If
    

    It is also important to ensure that the VBA macro disposes/destroys the WordApp object at some point in the code like this:

    Set WordApp = Nothing
    

    I wish you a great day!

    Best regards,

    Nelson Baleizão

    1 person found this answer helpful.
    0 comments No comments