Hi Dave
When the code inserts a picture into a table the picture is inserted as an
InlineShape, not a Shape, so Activedocument.Shapes.Count doesn't include it
in the count (Activedocument.InlineShapes.Count does). You could convert the
InlineShape to a Shape before adjusting its settings but I'm not sure what
the point of inserting an image into a table is if it doesn't stay in the
cell its inserted into, in which case I would think an InlineShape would be
appropriate.
InlineShapes and Shapes have different properties so while the code works ok
with shapes it doesn't with InlineShapes.
The code sets LockAspectRatio to True, but then sets both height and width,
regardless of whether those measurements maintain the aspect ratio for a
particular image. This works with Shapes in my testing, but with
InlineShapes setting both height and width negates the LockAspectRatio
setting, resulting in a distorted image.
I've rewritten the code as below to determine whether the picture is being
inserted in a table or not, then sets an object (objPic) and its appropriate
settings accordingly. I'm not sure what the SmallScroll line was supposed to
do (possibly a relic from macro recording) so I've deleted that line. I also
commented out the Height setting because it wasn't necessary for Shapes
(aspect ratio being locked) and it distorted InlineShapes in cells in my
testing. You can change which line to disable (Height or Width) as
appropriate, for instance depending on whether you want the image to fit the
height or width of a table cell.
There may be other ways of handling this situation but I tried to stick as
closely as possible to what you've got.
Sub InsertPic()
Dim iIndex As Integer
Dim ojbPic As Object
With Dialogs(wdDialogInsertPicture)
.FloatOverText = True
.Show
If .Name <> "" Then
If Selection.Information(wdWithInTable) = True Then
iIndex = ActiveDocument.InlineShapes.Count
Set objPic = ActiveDocument.InlineShapes(iIndex)
Else
iIndex = ActiveDocument.Shapes.Count
Set objPic = ActiveDocument.Shapes(iIndex)
'these properties are only applicable to Shapes
With objPic
.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionColumn
.RelativeVerticalPosition = _
wdRelativeVerticalPositionParagraph
.Left = InchesToPoints(0)
.Top = InchesToPoints(0)
.LockAnchor = False
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapBoth
.WrapFormat.DistanceTop = InchesToPoints(0)
.WrapFormat.DistanceBottom = InchesToPoints(0)
.WrapFormat.DistanceLeft = InchesToPoints(0.13)
.WrapFormat.DistanceRight = InchesToPoints(0.13)
.WrapFormat.Type = wdWrapTopBottom
End With
End If
'these properties apply to both Shapes and InlineShapes
With objPic
.Fill.Visible = False
.Fill.Visible = msoFalse
.Fill.Transparency = 0#
.Line.Weight = 0.75
.Line.DashStyle = msoLineSolid
.Line.Style = msoLineSingle
.Line.Transparency = 0#
.Line.Visible = msoFalse
.LockAspectRatio = msoTrue
' .Height = 129.6
.Width = 172.8
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.PictureFormat.ColorType = msoPictureAutomatic
.PictureFormat.CropLeft = 0#
.PictureFormat.CropRight = 0#
.PictureFormat.CropTop = 0#
.PictureFormat.CropBottom = 0#
.Line.Weight = 1#
.Line.Visible = msoTrue
End With
End If
End With
End Sub