Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 03-05-2015, 06:23 AM
gmayor's Avatar
gmayor gmayor is offline Can't copy image format from template Windows 7 64bit Can't copy image format from template Office 2010 32bit
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

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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't copy image format from template 1.image in a table 2.right click 3.menu click format 4.a format column appears OldFatDog Drawing and Graphics 1 06-13-2014 11:19 PM
OneNote - Copy and paste image to the table MartinK OneNote 0 09-03-2013 05:08 AM
Can't copy image format from template Copy text pastes image kfranken8 Word 2 07-12-2012 09:33 PM
Can't copy image format from template Vector image format jespestana Drawing and Graphics 4 11-26-2010 03:51 AM
Image Paste Format curtisdehaven Word 0 09-16-2009 04:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:05 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