1 Attachment(s)
Insert Multiple Pictures Into Table Word With Macro
Hello,
I would like to use a macro to insert several pictures in a table. In the first row the picture and in the second row the text "Pictures x"
look like attachment.
A have a bit of code.
[vba]
Sub Test()
'
' Test Macro
'
'
Dim fd As FileDialog
Dim oTbl As Table
Dim oILS As InlineShape
Dim vrtSelectedItem As Variant
'Add a 1 row 2 column table to take the images
Set oTbl = Selection.Tables.Add(Selection.Range, 2, 2)
With oTbl
.AutoFitBehavior (wdAutoFitFixed)
End With
With oTbl.Rows.First
.Height = CentimetersToPoints(7)
.HeightRule = wdRowHeightExactly
End With
With oTbl.Columns.First
.Width = CentimetersToPoints(7)
End With
With oTbl.Columns.Last
.Width = CentimetersToPoints(7)
End With
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Title = "Select image files and click OK"
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg; *.bmp; *.tif; *.png"
.FilterIndex = 2
If .Show = -1 Then
CaptionLabels.Add Name:="Picture"
For Each vrtSelectedItem In .SelectedItems
With Selection
Set oILS = .InlineShapes.AddPicture(FileName:= _
vrtSelectedItem, LinkToFile:=False, SaveWithDocument:=True, _
Range:=Selection.Range)
oILS.Range.InsertCaption Label:="Picture", TitleAutoText:="", Title:="", _
Position:=wdCaptionPositionBelow, ExcludeLabel:=0
.MoveRight wdCell, 1
End With
Next vrtSelectedItem
Else
End If
End With
If Len(oTbl.Rows.Last.Cells(1).Range) = 2 Then oTbl.Rows.Last.Delete
Set fd = Nothing
End Sub
[/vba]