Gheek.net

January 28, 2008

picture_resize_vba

Filed under: excel, microsoft, msword, vba — Tags: , , , , , , , — lancevermilion @ 12:19 am

Here is a handy script to resize images that are to big for your display and size wise.

The sad thing is I don’t recall if this works for any Microsoft Office application or just MSWord/Excel.

Answer
Glenn, I came across the follwing in one of my newsletters. This is exactly
what you are trying to do. I can't answer any questions about this macro
or any macros but this may solve the resizing problem for you.

Good luck.

Dale :-)

Scaling Graphics in a Macro

You may have a need to routinely scale graphics in your document by a
certain percentage. Using the menus to do the scaling can get tiresome,
so you may want to do the scaling by using a macro you can assign to a
toolbar button or a shortcut key. The following macro will handle doing
the scaling very nicely:

    Sub PictSize()
        Dim PecentSize As Integer

        PercentSize = InputBox("Enter percent of full size", "Resize Picture", 75)

        If Selection.InlineShapes.Count > 0 Then
            Selection.InlineShapes(1).ScaleHeight = PercentSize
            Selection.InlineShapes(1).ScaleWidth = PercentSize
        Else
            Selection.ShapeRange.ScaleHeight Factor:=(PercentSize / 100), _
              RelativeToOriginalSize:=msoCTrue
            Selection.ShapeRange.ScaleWidth Factor:=(PercentSize / 100), _
              RelativeToOriginalSize:=msoCTrue
        End If
    End Sub

The macro first asks for a percentage by which you want to scale the
selected image, offering 75 (75%) as the default. When you specify a
percentage, the macro then checks to see if the selected graphic is an
inline or a floating graphic. The reason for doing this is that the object
specification is different in each case, as well as how the scaling is specified.
Inline objects belong to the InlineShapes collection, while floating objects are
set using the ShapeRange object.

If you want to resize all the graphics in your document by the same
percentage, then you only need to modify the above macro so that it
steps through each of the inline graphics and then each of the floating
graphics.

    Sub AllPictSize()
        Dim PecentSize As Integer
        Dim oIshp As InlineShape
        Dim oshp As Shape

        PercentSize = InputBox("Enter percent of full size", "Resize Picture", 75)

        For Each oIshp In ActiveDocument.InlineShapes
            With oIshp
                .ScaleHeight = PercentSize
                .ScaleWidth = PercentSize
            End With
        Next oIshp

        For Each oshp In ActiveDocument.Shapes
            With oshp
                .ScaleHeight Factor:=(PercentSize / 100), _
                  RelativeToOriginalSize:=msoCTrue
                .ScaleWidth Factor:=(PercentSize / 100), _
                  RelativeToOriginalSize:=msoCTrue
            End With
        Next oshp
    End Sub

(Thanks to Yechezkel Missel, Lynn Taylor, and David G. Lett for
contributing to this tip.)

Hi Glenn,

Looks like you are in luck since there is a way to do just that sort of.

However, you will have to click on each picture but only set the
setting in the Format Picture dialog box just once.

First select all the picture in your document by selecting the first
one then hold down the Control Key (Ctrl) and select the rest of them.

Right-click on one off the pictures and choose Format Picture and
then the Size Tab

Type in 200 in the Height: box and make sure the Lock aspect
ration is checked and click OK.

Good Luck.

Dale :-)
Advertisements

Blog at WordPress.com.