#1
|
|||
|
|||
Copy table to another location in the same document
I have one table in document and want to copy it into another location (more precisely, bookmark location). For now I have the following code:
Code:
Dim doc As Document Dim t As Table Set doc = ThisDocument Set t = doc.Tables(1) t.Select Selection.Copy doc.Bookmarks("bm46").Select Selection.Paste |
#2
|
||||
|
||||
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 Code:
ActiveDocument.Bookmarks("bm46").Range.FormattedText = ActiveDocument.Tables(1).Range.FormattedText
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
macropod
Thanks a lot! Works perfectly! Word's object model is difficult, so I would never guess to write it the way you did. Once again - thanks! |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to have the location (path) of the Word document on the title bar? | Jamal NUMAN | Word | 24 | 09-06-2017 12:18 PM |
Open document file location issue help required | jborchel | Word | 8 | 10-21-2013 02:58 PM |
Displaying the filepath/document location in ribbon | MrPahoehoe | PowerPoint | 1 | 03-01-2013 06:41 AM |
VBA to copy bookmark to a new location | kent | Word VBA | 5 | 06-14-2012 02:18 PM |
table location, table title | pav | Word VBA | 1 | 05-24-2011 09:10 PM |