![]() |
#1
|
|||
|
|||
![]()
Hi,
I was trying to get macro for selecting certain tables and then copy them to a new document. I have got the code to select certain tables -but do not know how to copy these tables to new document Here is the code: Code:
Sub SelectRange() Dim rngParagraphs As Range Set rngParagraphs = ActiveDocument.Range( _ Start:=ActiveDocument.Tables(1).Range.Start, _ End:=ActiveDocument.Tables(8).Range.End) rngParagraphs.Select End Sub |
#2
|
||||
|
||||
![]()
Actually, you don't have to select anything. Once you have defined the range, make use of the Copy method, create a new document, and paste:
Code:
Dim rngParagraphs As Range Dim NewDoc As Document Set rngParagraphs = ActiveDocument.Range( _ Start:=ActiveDocument.Tables(1).Range.Start, _ End:=ActiveDocument.Tables(8).Range.End) rngParagraphs.Copy Set NewDoc = Documents.Add NewDoc.Content.Paste
__________________
Stefan Blom Microsoft Word MVP Microsoft 365 apps for business Windows 11 Professional |
#3
|
|||
|
|||
![]()
Thanks Stefan.
Can you suggest the macro which should do the same task as above however rather than we selecting the tables by (using the code (Tables (1) - Table (8)), the macro should select all the tables till the start of another heading of the document. Once selection is done then macro should copy and paste it to another document. Thanks. |
#4
|
||||
|
||||
![]()
Hi ubns,
This is the first time youve mentioned headings in this thread. For some code to process content between headings, see: https://www.msofficeforums.com/vba/1...ific-text.html You need to note that vba can't select multiple discontiguous ranges. So, if the there is anything between the tables, they have to be either: copied & pasted individually; or copied as a group along with the intervening content, which can then be deleted after pasting.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Thanks I have looked into that, however I dont know how can that code be helpful here?
|
#6
|
||||
|
||||
![]()
Hi ubns,
The code shows how one can continue extending a range until a certain heading (based on a heading Style) is reached. How/whether it might be helpful for you depends on what you're trying to achieve. However, since you haven't said anything about: what kinds of headings you're working with; how the starting point might be defined; or what content there might be between the tables you're interested in, no specific advice can be given.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
braddgood | Word VBA | 15 | 10-02-2015 01:54 PM |
![]() |
TishyMouse | Word VBA | 3 | 04-13-2012 03:26 AM |
![]() |
silverspr | Word VBA | 3 | 04-02-2011 11:20 PM |
Select Series Color - Macro | judicial85 | Excel Programming | 0 | 03-14-2011 02:35 PM |
![]() |
masa57 | Word VBA | 2 | 05-08-2010 07:34 AM |