View Single Post
 
Old 03-05-2015, 06:23 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
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

You can't select an item in a closed document - even if that document is the template. You need to open the template in order to copy from it e.g. as follows. The code assumes the process you envisaged was otherwise correct.

Code:
Sub Macro1()
Dim oSource As Document
Dim oTarget As Document
Dim i As Long
Dim j As Long
    If Documents.Count = 0 Then
        MsgBox "No document open!"
        GoTo lbl_Exit
    End If
    'Define the document to be processed
    Set oTarget = ActiveDocument
    'Open the source document
    Set oSource = Documents.Open(ThisDocument.FullName)

    'Find the shape that fits the criteria
    For j = 1 To oSource.InlineShapes.Count
        If oSource.InlineShapes(j).AlternativeText = " FIGURE_STYLE" Then
            oSource.InlineShapes(j).Select
            Selection.CopyFormat
            Exit For
        End If
    Next
    'Close the template
    oSource.Close 0
    'Find the shape to process
    For i = 1 To oTarget.InlineShapes.Count
        If oTarget.InlineShapes(i).Type = wdInlineShapePicture Then
            oTarget.InlineShapes(i).Select
            Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
            Selection.PasteFormat
        End If
    Next i
lbl_Exit:
    Set oSource = Nothing
    Set oTarget = Nothing
    Exit Sub
End Sub
Use the #CODE button and paste your code into the message rather than insert an image of the code. It makes it much easier to test your code.
__________________
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