View Single Post
 
Old 03-31-2014, 03:10 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,359
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If the idea is to replicate the table, you could just bookmark and cross-reference the bookmark.

As for your code, you don't need to select anything and you don't need either copy or paste and it doesn't provide for subsequent updates of the table (a new one will be inserted instead). Instead, try:
Code:
Sub TableDuplicate()
Dim BmkNm As String, BmkRng As Range
BmkNm = "bm46"
With ActiveDocument
  On Error Resume Next
  Set BmkRng = .Bookmarks(BmkNm).Range
  BmkRng.Tables(1).Delete
  BmkRng.FormattedText = .Tables(1).Range.FormattedText
  .Bookmarks.Add BmkNm, BmkRng
End With
Set BmkRng = Nothing
End Sub
Although the code is more complicated than yours, that's because of the overheads required to update, rather than just add to, the bookmarked content. Were that not a consideration, the code could be reduced to one line:
Code:
ActiveDocument.Bookmarks("bm46").Range.FormattedText = ActiveDocument.Tables(1).Range.FormattedText
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote