A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Assigning a name to the table



 
 
Thread Tools Display Modes
  #1  
Old February 6th, 2009, 08:39 AM posted to microsoft.public.word.tables
Rathish
external usenet poster
 
Posts: 42
Default Assigning a name to the table

Hi,
I need a help i am preparing a macro which will copy my table as it is and
paste it one after another in sequence. For the same i want to assign a name
to that table. Can any one help me regarding how i can name a table,
so that i can use that name in in my macro.
--
Thanks & Regards
Rathish
  #2  
Old February 7th, 2009, 06:48 PM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default Assigning a name to the table

Via VBA, you can assign a value to the ID of each table. In the example
below, the ID of each table in the active document is set to the current
index number. You could use descriptive names instead.

Dim n As Long

With ActiveDocument
For n = 1 To .Tables.Count
.Tables(n).ID = n
Next n
End With

You can then find a specific table by checking its ID. However, if you need
to copy the existing tables in succession, you can simply use the index
number of each table in order to refer to it. The following code will copy
each existing table in the document and paste it at the end of the document
with an empty paragraph after in order to separate the tables:


Sub CopyEachTable_InsertAtEndOfDocument()

Dim n As Long
Dim orange As Range
Dim nTables As Long

nTables = ActiveDocument.Tables.Count

For n = 1 To nTables
ActiveDocument.Tables(n).Range.Copy
Set orange = ActiveDocument.Range
With orange
.Collapse (wdCollapseEnd)
'Paste the copied table
.Paste
'Insert empty paragraph to separate tables
'Skip if last table
If n nTables Then
.Collapse (wdCollapseEnd)
.InsertAfter vbCr
End If
End With
Next n

'Clean up
Set orange = Nothing

End Sub

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Rathish" wrote:

Hi,
I need a help i am preparing a macro which will copy my table as it is and
paste it one after another in sequence. For the same i want to assign a name
to that table. Can any one help me regarding how i can name a table,
so that i can use that name in in my macro.
--
Thanks & Regards
Rathish

  #3  
Old February 7th, 2009, 07:18 PM posted to microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default Assigning a name to the table

Via VBA, you can assign a value to the ID of each table. In the example
below, the ID of each table in the active document is set to the current
index number. You could use descriptive names instead.

Dim n As Long

With ActiveDocument
For n = 1 To .Tables.Count
.Tables(n).ID = n
Next n
End With

You can then find a specific table by checking its ID. However, if you need
to copy the existing tables in succession, you can simply use the index
number of each table in order to refer to it. The following code will copy
each existing table in the document and paste it at the end of the document
with an empty paragraph after in order to separate the tables:


Sub CopyEachTable_InsertAtEndOfDocument()

Dim n As Long
Dim orange As Range
Dim nTables As Long

nTables = ActiveDocument.Tables.Count

For n = 1 To nTables
ActiveDocument.Tables(n).Range.Copy
Set orange = ActiveDocument.Range
With orange
.Collapse (wdCollapseEnd)
'Paste the copied table
.Paste
'Insert empty paragraph to separate tables
'Skip if last table
If n nTables Then
.Collapse (wdCollapseEnd)
.InsertAfter vbCr
End If
End With
Next n

'Clean up
Set orange = Nothing

End Sub

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Rathish" wrote:

Hi,
I need a help i am preparing a macro which will copy my table as it is and
paste it one after another in sequence. For the same i want to assign a name
to that table. Can any one help me regarding how i can name a table,
so that i can use that name in in my macro.
--
Thanks & Regards
Rathish

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:24 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.