View Single Post
 
Old 07-25-2018, 08:31 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Try the following which is trapped against the usual errors.



Code:
Option Explicit

Sub CopyStyle()
Dim oSource As Document
Dim oTarget As Document
Dim strFullName As String
Dim fso As Object
    strFullName = Environ("USERPROFILE") & "\Desktop\EXAMPLE.docx"
    On Error Resume Next
    If LCase(ActiveDocument.FullName) = LCase(strFullName) Then
        MsgBox "The active document is the style source document!"
        GoTo lbl_Exit
    End If
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oTarget = ActiveDocument
    oTarget.Save
    If oTarget.Path = "" Then
        MsgBox "The document must be saved!"
        GoTo lbl_Exit
    End If
    If fso.FileExists(strFullName) Then
        Set oSource = Documents.Open(FileName:=strFullName, _
                                     Visible:=False, _
                                     AddToRecentFiles:=False)
        Application.OrganizerCopy Source:= _
                                  oSource.FullName, Destination:= _
                                  oTarget.FullName, _
                                  Name:="Caption-Photo", _
                                  Object:=wdOrganizerObjectStyles
        oSource.Close
    Else
        MsgBox strFullName & " is not available"
    End If
lbl_Exit:
    Set oTarget = Nothing
    Set oSource = Nothing
    Set fso = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote