Sub centerPictures()
Dim shpIn As InlineShape, shp As Shape
For Each shpIn In ActiveDocument.InlineShapes
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next shpIn
For Each shp In ActiveDocument.Shapes
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next shp
End Sub

For something that turns out to be super-easy, there was not one place on the web that I could find this information. I needed to programmatically center all images in a Word document using Visual Basic for Applications (VBA). I searched high and low, and while I could find how to loop through all images, I couldn’t find how to center them. Then I turned to the macro writer’s best friend: the macro recorder. Duh! :blush:

It actually took me longer to find a document with pictures than it did to record the macro, see what it did, add it to my loops (see below), and test it.

You’ll notice that there are two loops in the code. That is so that it picks up inline figures as well wrapped figures.

CC BY-NC-SA 4.0 Word一键居中所有图片 by 桔子小窝 is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.