Fix Word VBA Error 5174 When Reopening a SharePoint Document
Question details
Reopen a SharePoint document after saving and closing it with a Word VBA macro.

- Product
- Microsoft Word VBA and SharePoint
- Device & OS
- not provided
- Scenario
- A macro saves, closes, and reopens a Word document stored in SharePoint.
- Observed behavior
- The macro may show run-time error 5174, stop when its host document closes, or briefly display a blank screen.
Open the intended SharePoint document in Word and check whether the macro is stored in that document, a template, or an add-in. Make sure you have access to the document's SharePoint location.
Save the document path and reopen it from a template or add-in
Use the document's full path as a variable and keep the running macro outside the document being closed.
Press Alt+F11 to open the VBA editor. If the macro is stored in the document it closes, move it to a template or add-in that remains open.
In the VBA editor, set a Document variable to ActiveDocument and save its FullName before closing it. ThisDocument refers to the template or add-in when the macro is stored there, not necessarily the SharePoint document.
Use the saved variable without quotation marks in Documents.Open. For example: Sub ReopenSharePointDocument() Dim doc As Document Dim strPath As String Set doc = ActiveDocument strPath = doc.FullName doc.Save doc.Close SaveChanges:=wdDoNotSaveChanges Documents.Open FileName:=strPath End Sub
Activate the intended SharePoint document in Word, then run the macro from Developer > Macros. If error 5174 persists, check that the saved path is accessible and points to the intended document.

Edit Word Documents with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word files. Its format compatibility helps you move existing documents into WPS, although it does not fix Microsoft Word VBA errors.

Frequently Asked Questions
Why does Documents.Open("strPath") cause error 5174?
The quotation marks make strPath literal text rather than the variable's value. Use Documents.Open FileName:=strPath to pass the saved path.
Should I use ThisDocument or ActiveDocument?
ThisDocument refers to the document or template containing the macro. If the macro is in a template or add-in, use ActiveDocument to identify the document being edited, and capture its FullName before closing it.
Why does the macro stop after closing the document?
If the running macro is stored in the document being closed, closing that document can stop execution. Move the macro to a template or add-in that remains open.
Can I prevent the screen from going blank while Word reopens the file?
Application.ScreenUpdating = False may reduce screen updates, but it does not guarantee a blank screen will disappear. Set it back to True after the operation, including in error handling.




