When running the following code with the document I want to replace the style in open, I get a "File in Use" (Test.docx is locked for editing... ) window.
It seems to make a different how the file is opened though, and I am hoping one of you can explain why that is. If I open the file using File >Open within Word and then run the macro, it works. However, that is not a typical workflow for me—I usually open a file by clicking on it.
Code:
Sub ReplaceStyles()
Dim DocSource
Dim myFile
DocSource = "C:\Users\myname\Desktop\EXAMPLE.docx"
Set myFile = ActiveDocument
'myFile = "full path to document.docx"
Application.OrganizerCopy Source:=DocSource, Destination:=myFile, Object:=wdOrganizerObjectStyles, _
Name:="Caption-Photo"
End Sub
The eventual code will update/add many styles. I wish to do this via a macro rather than attaching a template.
Word 2010, Windows 7