Consulting

Results 1 to 20 of 53

Thread: Insert Multiple Pictures Into Table Word With Macro

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Nov 2012
    Posts
    12
    Location

    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]
    Attached Images Attached Images

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •