View Single Post
 
Old 07-06-2018, 12:19 AM
Guessed's Avatar
Guessed Guessed is online now Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,980
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Try this code - the macro is called ReplaceImages. It is written to run from the current selection point to the end of the document and continuously open the usual dialog until it runs out of pictures in the document.
It doesn't include a method of breaking the code if choose to stop before reaching the end of the document. The logical way to do that would be to detect if a dialog was dismissed by pressing Cancel but I'm not sure how I would do that. Someone else might have a good idea on how to do that.
Code:
Sub ReplaceImages()
  Dim i As Integer, aRng As Range
  Set aRng = Selection.Range
  aRng.End = ActiveDocument.Range.End
  For i = 1 To aRng.InlineShapes.Count
    aRng.InlineShapes(i).Select
    funReplaceInlineShape aRng.InlineShapes(i)
  Next i
End Sub

Function funReplaceInlineShape(origShp As InlineShape) As Boolean
  Select Case origShp.Type
    Case msoAutoShape, msoFreeform, 6   'this is a shape with a picture fill
      CommandBars.ExecuteMso ("ObjectPictureFill")
    Case wdInlineShapePicture      'this is a picture placed into the doc
      If CInt(Application.Version) < 16 Then   'following only works pre Word 2016+
          CommandBars.ExecuteMso ("PictureChange")
        Else                    'following is for Word 2016+
          CommandBars.ExecuteMso ("PictureChangeFromFile")
      End If
  End Select
End Function
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote