![]() |
#3
|
||||
|
||||
![]()
At its most basic, assume your PNGs are all in the same folder as the Word document. Then this code will iterate through a column of text to add the corresponding image in the preceding cell
Code:
Sub InsertImages() Dim aCell As Cell, sPath As String, sFile As String, aTbl As Table, iCol As Integer Dim aRng As Range, aShp As InlineShape Set aTbl = Selection.Tables(1) iCol = Selection.Cells(1).Column.Index sPath = ActiveDocument.Path & Application.PathSeparator For Each aCell In aTbl.Columns(iCol).Cells sFile = sPath & Split(aCell.Range.Text, vbCr)(0) & ".png" If Len(Dir(sFile)) > 0 Then Debug.Print sFile Set aRng = aCell.Previous.Range Set aShp = ActiveDocument.InlineShapes.AddPicture(FileName:=sFile, Range:=aRng) aShp.AlternativeText = sFile aShp.Width = CentimetersToPoints(0.8) aShp.Height = CentimetersToPoints(0.8) aRng.Cells(1).VerticalAlignment = wdCellAlignVerticalCenter aRng.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter End If Next aCell End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Nina | Word VBA | 16 | 08-27-2018 01:53 AM |
![]() |
nando88 | Word VBA | 6 | 05-09-2016 11:56 PM |
![]() |
skatiemcb | Word Tables | 2 | 01-24-2015 08:18 AM |
![]() |
mescaL | Word VBA | 3 | 11-03-2014 10:51 PM |
![]() |
JBA479 | Word VBA | 1 | 01-24-2014 08:51 PM |