vba delete current tables, paste and link new tables in word based on caption

alexb523

Board Regular
Joined
Dec 12, 2013
Messages
115
Hello,

I have a large word document which contains tables and "captions" associated with those tables. The tables are updated annually, so i need to link them and excel document which i can update annually or if a mistake is found etc.

What i am currently thinking, since each of my tables has the necessary caption, is to use vba to find the caption, delete the below table, and then paste a new table with via "html link".

Please let me know what you if this is possible or if there is a better solution.

Thanks,
Alex
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hello

Tell me if this code deletes the table under a certain caption, and then we can proceed.


Code:
' Word module
Sub Sample()
Dim c As Range, StartWord As String, EndWord$
StartWord = "Start": EndWord = "End"
Set c = ActiveDocument.Content
c.Find.ClearFormatting
c.Find.Replacement.ClearFormatting
With c.Find
    .Text = StartWord & "*" & EndWord
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = True
End With
c.Find.Execute
If c.Find.Found Then
    c.Select
    With Selection
        .GoTo wdGoToTable, wdGoToNext, 1
        .Tables(1).Delete
    End With
End If
End Sub
 
Upvote 0
So why not simply copy the tables and paste them into Word as a link once, then update the link paths each year if necessary?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top