Format a Picture in MS Word
I am trying to write a simple macro to select an image, inserted it into Word, and then format it. I’ve cobbled together some code which sizes it properly but does not set the Wrap Text to “tight” correctly. Can anyone help me fix this issue?
Sub FormatImage()
‘ FormatImage Macro
‘
Dim fileSelected As Variant
Dim fileOpenDialog As FileDialog
Dim newPicture As InlineShape
Set fileOpenDialog = Application.FileDialog(msoFileDialogOpen)
Selection.Delete
‘Unit:=wdCharacter, Count:=1
With fileOpenDialog
.AllowMultiSelect = False
.Filters.Add “Images”, “*.gif; *.jpg; *.jpeg”, 1
If .Show = -1 Then
fileSelected = .SelectedItems(1)
Else
Exit Sub
End If
End With
Set newPicture = Selection.InlineShapes.AddPicture(FileName:=fileSelected, LinkToFile:=False, SaveWithDocument:=True)
With newPicture
.LockAspectRatio = msoFalse
.Height = InchesToPoints(1.25)
.Width = InchesToPoints(0.85)
End With
If Selection.ShapeRange.Count = 0 Then
If Selection.InlineShapes.Count = 1 Then
Selection.InlineShapes(1).ConvertToShape
Else
MsgBox “Select a picture first.”, , “Oops!”
End If
End If
With Selection.ShapeRange(1)
With .WrapFormat
.Type = wdWrapTight
End With
End With
End Sub
I am trying to write a simple macro to select an image, inserted it into Word, and then format it. I’ve cobbled together some code which sizes it properly but does not set the Wrap Text to “tight” correctly. Can anyone help me fix this issue? Sub FormatImage()’ FormatImage Macro’Dim fileSelected As VariantDim fileOpenDialog As FileDialogDim newPicture As InlineShapeSet fileOpenDialog = Application.FileDialog(msoFileDialogOpen)Selection.Delete’Unit:=wdCharacter, Count:=1With fileOpenDialog.AllowMultiSelect = False.Filters.Add “Images”, “*.gif; *.jpg; *.jpeg”, 1If .Show = -1 ThenfileSelected = .SelectedItems(1)ElseExit SubEnd IfEnd WithSet newPicture = Selection.InlineShapes.AddPicture(FileName:=fileSelected, LinkToFile:=False, SaveWithDocument:=True)With newPicture.LockAspectRatio = msoFalse.Height = InchesToPoints(1.25).Width = InchesToPoints(0.85)End WithIf Selection.ShapeRange.Count = 0 ThenIf Selection.InlineShapes.Count = 1 ThenSelection.InlineShapes(1).ConvertToShapeElseMsgBox “Select a picture first.”, , “Oops!”End IfEnd IfWith Selection.ShapeRange(1)With .WrapFormat.Type = wdWrapTightEnd WithEnd WithEnd Sub Read More