View Single Post
 
Old 07-07-2017, 06:28 AM
lodi123 lodi123 is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Feb 2017
Posts: 10
lodi123 is on a distinguished road
Default Inserting graphic in last table

Hi guys,

I'm wondering if there is a possibility to refer to the last table in a Word document.
I need to insert a graphic in the last table, but it is possible that the number of tables inside the document will change. So I can't use the Tables(X) in the code.

Now I got this:
Sub ShowInterim(control As IRibbonControl)

With ActiveDocument
Dim oBB As BuildingBlock
Dim oRng As Range
Dim oField As Field
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter

Set oRng = ActiveDocument.Tables(18).Rows(1).Cells(1).Range
oRng.End = oRng.End - 1 'to exclude the end of cell marker
Set oBB = ActiveDocument.AttachedTemplate.BuildingBlockEntri es("Interim")
oBB.Insert Where:=oRng, RichText:=True
For Each oSection In ActiveDocument.Sections

For Each oHeader In oSection.Headers
If oHeader.Exists Then
For Each oField In oHeader.Range.Fields
oField.Update
Next oField
End If
Next oHeader
Next oSection

End With

End Sub

Is there a possibility like Table(Last) or something to fix this? The last table will also be on the last page of the document, if this helps.
Reply With Quote