PDA

View Full Version : Replacing a Shape in word using VBA ( location)



marylin123
04-07-2016, 06:23 AM
I have a macro in MS Word that replaces the header and footer and any text that matches requirements from a master document into all other documents in a a directory. This works perfectly.
I have also got the macro working to select the InlineShape in the documents and replace it with an inline shape from the master document. The problem I'm having is trying to do this with a Shape (image set behind text).
The select and replace functions dont seem to work and when I have got them working the image isnt replaced in the same place in the document.
Any help would be appreciated as I'm going crazy trying to get this to work!!
Thanks
'IMAGE CHANGE
'Select and copy the InlineShape in the template
wdDocSrc.InlineShapes(1).Select
With Selection
.Copy
End With

'Select the inlineshape in the letter, delete it and paste (already copied the
'image in the code above) then loop for every inline image in the document.

For i = wdDocTgt.InlineShapes.Count To 1 Step -1
wdDocTgt.InlineShapes(i).Select
With Selection
.Delete
.PasteSpecial
End With
Next i


'Select and copy the SHAPES in the template
wdDocSrc.Shapes(1).Select
With Selection
.Copy
End With

'Select the SHAPE in the letter, delete it and paste (already copied the
'image in the code above) then loop for every inline image in the document.






'Save changes to the wdDocTgt and close it
.Close SaveChanges:=True
End With
End If

strFile = Dir()
Wend
MsgBox "Macro Complete"
Set wdDocSrc = Nothing: Set wdDocTgt = Nothing
Application.ScreenUpdating = True
End Sub