Question : Locking aspect ratio doesn't work in recorded macro

I would like to know if "lockaspectratio" property of MS Word inlineshapes does work.

I tried recording a macro that will resize all picture widths of my document to exactly 4cm (113.4pt). When I record the macro I click on the first image, then open the Image Format dialog, check "Lock Aspect Ratio", then select the new width (4cm) and then click ok. Then I move from one cell to another of the table containing the pictures using TAB and keep clicking the F4 key (this will repeat the last operation).

This resizing perfectly works. What it is weird to me is that If I don't save the document, then reopen it, then click again on the first picture and re-run the recorded macro, aspect ratio is not locked: proportions are all wrong.

You can see the recorded macro in the attached code.

What it is weird is that all widths and heights in the macro are the same (or it is not weird?) even if the widths and heights of the original pictures are different.

I realized that I could modify the VB code by calcuting by myself the new proportional widths and heights by doing something like this:

        With Selection.InlineShapes(1)
            ImageWidth = .Width
            ImageHeight = .Height
            NewWidth = 113.4
            NewHeight = Round(NewWidth * ImageHeight / ImageWidth)
            .Height = NewHeight
            .Width = NewWidth
        End With

But, as I said, I would like to be able to get to the same result by recording a macro.

I attached the Word document with the table and the pictures (without macros as they are stored in teh normal model). To run the ResizeWithF4 macro, remeber to click on the first picture before.

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
Sub ResizeWithF4()
'
' ResizeWithF4 Macro
' Macro registrata il 03/03/2008 da test
'
    Selection.InlineShapes(1).Fill.Visible = msoTrue
    Selection.InlineShapes(1).Fill.Solid
    Selection.InlineShapes(1).Fill.ForeColor.RGB = RGB(255, 255, 255)
    Selection.InlineShapes(1).Fill.Transparency = 0#
    Selection.InlineShapes(1).Line.Weight = 0.75
    Selection.InlineShapes(1).Line.Transparency = 0#
    Selection.InlineShapes(1).Line.Visible = msoFalse
    Selection.InlineShapes(1).LockAspectRatio = msoTrue
    Selection.InlineShapes(1).Height = 85.05
    Selection.InlineShapes(1).Width = 113.4
    Selection.InlineShapes(1).PictureFormat.Brightness = 0.5
    Selection.InlineShapes(1).PictureFormat.Contrast = 0.5
    Selection.InlineShapes(1).PictureFormat.ColorType = msoPictureAutomatic
    Selection.InlineShapes(1).PictureFormat.CropLeft = 0#
    Selection.InlineShapes(1).PictureFormat.CropRight = 0#
    Selection.InlineShapes(1).PictureFormat.CropTop = 0#
    Selection.InlineShapes(1).PictureFormat.CropBottom = 0#
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.InlineShapes(1).Fill.Visible = msoTrue
    Selection.InlineShapes(1).Fill.Solid
    Selection.InlineShapes(1).Fill.ForeColor.RGB = RGB(255, 255, 255)
    Selection.InlineShapes(1).Fill.Transparency = 0#
    Selection.InlineShapes(1).Line.Weight = 0.75
    Selection.InlineShapes(1).Line.Transparency = 0#
    Selection.InlineShapes(1).Line.Visible = msoFalse
    Selection.InlineShapes(1).LockAspectRatio = msoTrue
    Selection.InlineShapes(1).Height = 85.05
    Selection.InlineShapes(1).Width = 113.4
    Selection.InlineShapes(1).PictureFormat.Brightness = 0.5
    Selection.InlineShapes(1).PictureFormat.Contrast = 0.5
    Selection.InlineShapes(1).PictureFormat.ColorType = msoPictureAutomatic
    Selection.InlineShapes(1).PictureFormat.CropLeft = 0#
    Selection.InlineShapes(1).PictureFormat.CropRight = 0#
    Selection.InlineShapes(1).PictureFormat.CropTop = 0#
    Selection.InlineShapes(1).PictureFormat.CropBottom = 0#
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.InlineShapes(1).Fill.Visible = msoTrue
    Selection.InlineShapes(1).Fill.Solid
    Selection.InlineShapes(1).Fill.ForeColor.RGB = RGB(255, 255, 255)
    Selection.InlineShapes(1).Fill.Transparency = 0#
    Selection.InlineShapes(1).Line.Weight = 0.75
    Selection.InlineShapes(1).Line.Transparency = 0#
    Selection.InlineShapes(1).Line.Visible = msoFalse
    Selection.InlineShapes(1).LockAspectRatio = msoTrue
    Selection.InlineShapes(1).Height = 85.05
    Selection.InlineShapes(1).Width = 113.4
    Selection.InlineShapes(1).PictureFormat.Brightness = 0.5
    Selection.InlineShapes(1).PictureFormat.Contrast = 0.5
    Selection.InlineShapes(1).PictureFormat.ColorType = msoPictureAutomatic
    Selection.InlineShapes(1).PictureFormat.CropLeft = 0#
    Selection.InlineShapes(1).PictureFormat.CropRight = 0#
    Selection.InlineShapes(1).PictureFormat.CropTop = 0#
    Selection.InlineShapes(1).PictureFormat.CropBottom = 0#
    Selection.MoveRight Unit:=wdCell
    Selection.MoveRight Unit:=wdCell
    Selection.InlineShapes(1).Fill.Visible = msoTrue
    Selection.InlineShapes(1).Fill.Solid
    Selection.InlineShapes(1).Fill.ForeColor.RGB = RGB(255, 255, 255)
    Selection.InlineShapes(1).Fill.Transparency = 0#
    Selection.InlineShapes(1).Line.Weight = 0.75
    Selection.InlineShapes(1).Line.Transparency = 0#
    Selection.InlineShapes(1).Line.Visible = msoFalse
    Selection.InlineShapes(1).LockAspectRatio = msoTrue
    Selection.InlineShapes(1).Height = 85.05
    Selection.InlineShapes(1).Width = 113.4
    Selection.InlineShapes(1).PictureFormat.Brightness = 0.5
    Selection.InlineShapes(1).PictureFormat.Contrast = 0.5
    Selection.InlineShapes(1).PictureFormat.ColorType = msoPictureAutomatic
    Selection.InlineShapes(1).PictureFormat.CropLeft = 0#
    Selection.InlineShapes(1).PictureFormat.CropRight = 0#
    Selection.InlineShapes(1).PictureFormat.CropTop = 0#
    Selection.InlineShapes(1).PictureFormat.CropBottom = 0#
End Sub
Open in New Window Select All

Answer : Locking aspect ratio doesn't work in recorded macro

Cindy Meister (well known as the international Word guru) replied.

She was aware of it, and thinks it has never worked, so I'm afraid you're stuck with the getaround that you've already worked out.
Random Solutions  
 
programming4us programming4us