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
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
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.
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
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"
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