I am attempting to take images from one open file and put them into tables. I know that the below code will insert text into each cell:
[VBA]
Sub CreateNewTable()
Dim docActive As Document
Dim tblNew As Table
Dim celTable As Cell
Dim intCount As Integer
Set docActive = ActiveDocument
intCount = 1
For i = 1 to 4
Set tblNew = docActive.tables(i)
For Each celTable In tblNew.Range.Cells
celTable.Range.InsertAfter "Cell " & intCount
intCount = intCount + 1
Next celTable
Next i
End Sub
[/VBA]
Based on this, I tried the following:
[VBA]
Sub Table_Select()
Dim docActive As Document
Dim tblNew As Table
Dim celTable As Cell
Dim intCount As Integer
Set docActive = ActiveDocument
'Set tblNew = docActive.Tables.Add( _
' Range:=docActive.Range(Start:=0, End:=0), NumRows:=3, _
' NumColumns:=4)
intCount = 1
Let Initial = 0
For i = 1 To 4
Set tblNew = docActive.Tables(i)
Let intCount = 1
For Each celTable In tblNew.Range.Cells
'Copy Image
Documents("Document2").Activate
ActiveDocument.Shapes(intCount + Initial).Select
Selection.Copy
'Clear and Paste Image
Documents(docActive).Activate
celTable.Range.Delete
celTable.Range.Select
celTable.Range.PasteAndFormat (wdPasteDefault)
intCount = intCount + 1
Next celTable
Let Initial = intCount
'tblNew.AutoFormat Format:=wdTableFormatColorful2,
' ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True
Next i
End Sub
[/VBA]
However, when I run this code, it sticks all the images in the 1st Cell (Cell(1,1)) of the table. It does not progress through the table.
Does anyone know a way to do this?
Thanks for your time.