Make sure your Reference is added.
Excel VBA, error message 4198 when computer is offline
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.
12 answers
Sort by: Most helpful
-
Anonymous
2024-05-29T02:00:01+00:00 -
Anonymous
2024-05-29T06:20:01+00:00 Thank you for your response! This reference is already added.
Please note that the macro work when computer is connected to internet. Additionally, macro works when computer is offline from internet WHEN word file is located on USB drive.
Error message 4198 comes exclusively when computer is offline and when Word file to open is stored on local computer such as desktop or documents.
Code generating error message 4198:
WordApp.Documents.Open FileNameTemplate
-
Anonymous
2024-05-29T06:29:00+00:00 Could you share the file name template path (without sensitive information) to reproduce your issue? I will have a try on it.
Is it possible to share the entire code or test file?
-
Anonymous
2024-05-29T08:19:54+00:00 Hello, thanks a lot for your help! Please find VBA code. Text in red/bold cause error code 4198 when computer is offline. No problems when computer is online.
Sub WordDocument_()
Dim WordApp As Word.Application
Dim myDoc As Word.Document
Filename = "C:\Users\SETUWLE\OneDrive - User name\Desktop\V11\Word templates\Word template, test form.docx"
Set WordApp = CreateObject("word.Application") **WordApp.Documents.Open Filename** WordApp.Visible = TrueEnd sub
-
Anonymous
2024-05-29T08:37:48+00:00 You may try opening locals windows then use F8 to Run your code step by step. Check the difference when you are online and offline for the "Filename".
View >locals windows