PDA

View Full Version : Formatting all pictures in word document



Angelfish13
12-22-2014, 01:14 PM
Hello,

I have built macros for excel before but this is my first time attempting to build a macro with word.

I have a document of approximately 800 images. I need all of these images to be formatted to be in front of text. This is what I tried and it did not work, I got an error message. It seems like this should be so simple but I cannot figure out what is wrong. Please help, thank you!

Sub Pictures()
'
Dim Pic As InlineShape
For Each Pic In ActiveDocument.InlineShapes
Pic.Select
Selection.ShapeRange.WrapFormat.Type = wdWrapFront
Next
End Sub

Dave
12-22-2014, 08:21 PM
What version of Office are U using and how did the pictures get there? Maybe it's that Converttoshape thing? Dave

macropod
12-22-2014, 08:31 PM
Dave: The Office version isn't relevant.

Angelfish: Since Pic is an InlineShape, it doesn't have a ShapeRange property. Try:

Sub Pictures()
Application.ScreenUpdating = False
Dim Pic As InlineShape, Shp As Shape
With ActiveDocument
For Each Pic In .InlineShapes
Pic.ConvertToShape
Next
For Each Shp In ActiveDocument.Shapes
Shp.WrapFormat.Type = wdWrapFront
Next
End With
Application.ScreenUpdating = True
End Sub
The above code will convert the pictures to in-front wrapping regardless of whether they're presently formatted as inlineshapes or anything else.

Dave
12-22-2014, 09:22 PM
Paul: Word for Office 13 apparently has difficulties with pics and pasting was the reason for the version inquiry. I think that I almost understand the convertoshape thing and purpose now. Thanks. Dave

macropod
12-22-2014, 09:39 PM
I am not aware of any particular issues Word 2013 has with pics and, in any event, the VBA code for all Word versions is the same insofar as this thread is concerned.