Resize and rotate all images in a Word 2010 document

Just a little snippet to resize and rotate all images in a Word 2010 document. I needed it to create a table with multiple images per row/column from some dragged and dropped images.

  1. Option Explicit
  2. Sub ResizeAndRotateAllImages()
  3.  
  4. Const ROTATION = 90
  5. Const HEIGHT = 7
  6.  
  7. Dim n As Integer
  8.  
  9. For n = 1 To ActiveDocument.InlineShapes.Count
  10.     With ActiveDocument.InlineShapes(1)
  11.         .ScaleHeight = HEIGHT
  12.         .ConvertToShape
  13.     End With
  14. Next n
  15.  
  16. For n = 1 To ActiveDocument.Shapes.Count
  17.     With ActiveDocument.Shapes(1)
  18.         .IncrementRotation (ROTATION)
  19.         .ConvertToInlineShape
  20.     End With
  21. Next n
  22.  
  23. End Sub

Apparently, you have to convert the inserted images from InlineShape to Shape and back as both types provide different methods (e.g. only Shape offers IncrementRotation).

Über uns Stefan

Polyglot Clean Code Developer

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax