views:

810

answers:

3

I found a VBA macro online that resizes all the images in a Word document:

Sub ResizeAllImages()
''# make all images (both inline and floating)
''# 11 cm wide while preserving aspect ratio

Dim oShp As Shape
Dim oILShp As InlineShape

For Each oShp In ActiveDocument.Shapes
    With oShp
        .Height = AspectHt(.Width, .Height, _
        CentimetersToPoints(11))
        .Width = CentimetersToPoints(11)
    End With
Next

For Each oILShp In ActiveDocument.InlineShapes
    With oILShp
        .Height = AspectHt(.Width, .Height, _
        CentimetersToPoints(11))
        .Width = CentimetersToPoints(11)
    End With
Next
End Sub

I couldn't find the name of a method that I could use to center-align all images. Does anyone know what I need to add, and where I would have to add it?

Lastly, I'd like to delete images that I find to be too small. How would I do... If width of shape is smaller than 5, and height of shape is smaller than 5, delete the shape.

For easier reading of large amounts of online text, I sometimes like to paste everything in word, and then rearrange it. I replace every period-whitespace, with a period-manual line, which gives me a new line for each sentence.. I read better when it's like that. Since I'm pasting everything, the graphics comes too, so I'd like to be able to control the size of all the images, and get rid of any unnecessary images.

A: 

I think you cannot center-align images. You can center-align paragraphs. Perhaps something like this will help you:

For Each oILShp In ActiveDocument.InlineShapes
    oILShp.Select
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next

For deletion, just call Delete for each Shape object satisfying your conditions.

Doc Brown
Thanks.That piece of code worked.
bbint
A: 

Code to delete small pictures:

Sub DeleteSmallPictures()
Dim iShp As InlineShape

    For Each iShp In ActiveDocument.InlineShapes
        With iShp
            If .Width < CentimetersToPoints(5) Then
                iShp.Delete
            End If
        End With
    Next iShp
End Sub
bbint
A: 

Can you help me? I need to extract images from word file to picturebox without using macro

Michael