View Single Post
 
Old 07-24-2018, 07:52 PM
AnnaNmty AnnaNmty is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2018
Posts: 2
AnnaNmty is on a distinguished road
Default OrganizerCopy method for ActiveDocument

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
Reply With Quote