Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-25-2018, 08:31 PM
gmayor's Avatar
gmayor gmayor is offline OrganizerCopy method for ActiveDocument Windows 10 OrganizerCopy method for ActiveDocument Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 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
Reply

Tags
active document, styles



Similar Threads
Thread Thread Starter Forum Replies Last Post
OrganizerCopy method for ActiveDocument Loop through listboxes in Application.OrganizerCopy Marrick13 Word VBA 50 04-16-2024 01:21 PM
ActiveDocument.ContentControls(ID) not working Tejas.T Word VBA 3 03-09-2015 06:50 PM
Loop through listboxes in Application.OrganizerCopy-revisited Marrick13 Word VBA 0 12-06-2014 06:07 AM
wordapp.ActiveDocument.SaveAs Not Working KSReynolds Mail Merge 1 07-18-2014 04:03 PM
OrganizerCopy method for ActiveDocument Using With ActiveDocument.Tables() SuzeG Word VBA 1 01-08-2014 02:00 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft