![]() |
|
|
|
#1
|
||||
|
||||
|
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 |
|
| Tags |
| active document, styles |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
Using With ActiveDocument.Tables()
|
SuzeG | Word VBA | 1 | 01-08-2014 02:00 PM |