Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2012, 09:22 PM
ubns ubns is offline Macro to select tables Windows 7 32bit Macro to select tables Office 2010 32bit
Competent Performer
Macro to select tables
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default Macro to select tables

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
Reply With Quote
  #2  
Old 04-14-2012, 12:36 PM
Stefan Blom's Avatar
Stefan Blom Stefan Blom is online now Macro to select tables Windows 7 64bit Macro to select tables Office 2010 32bit
Moderator
 
Join Date: Aug 2011
Posts: 3,872
Stefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to allStefan Blom is a name known to all
Default

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
Reply With Quote
  #3  
Old 04-15-2012, 04:08 PM
ubns ubns is offline Macro to select tables Windows 7 32bit Macro to select tables Office 2010 32bit
Competent Performer
Macro to select tables
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 04-15-2012, 06:29 PM
macropod's Avatar
macropod macropod is offline Macro to select tables Windows 7 64bit Macro to select tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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]
Reply With Quote
  #5  
Old 04-15-2012, 10:29 PM
ubns ubns is offline Macro to select tables Windows 7 32bit Macro to select tables Office 2010 32bit
Competent Performer
Macro to select tables
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

Thanks I have looked into that, however I dont know how can that code be helpful here?
Reply With Quote
  #6  
Old 04-15-2012, 11:44 PM
macropod's Avatar
macropod macropod is offline Macro to select tables Windows 7 64bit Macro to select tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to select tables Macro to delete all empty rows from all tables braddgood Word VBA 15 10-02-2015 01:54 PM
Macro to select tables Can't select shapes via macro TishyMouse Word VBA 3 04-13-2012 03:26 AM
Macro to select tables Word Macro to search all tables silverspr Word VBA 3 04-02-2011 11:20 PM
Select Series Color - Macro judicial85 Excel Programming 0 03-14-2011 02:35 PM
Macro to select tables I need a macro that removes background of many tables masa57 Word VBA 2 05-08-2010 07:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:17 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft