Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Rathish Rathish is offline
external usenet poster
 
Posts: 33
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   Report Post  
Posted to microsoft.public.word.tables
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
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   Report Post  
Posted to microsoft.public.word.tables
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
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

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning shortcut keys Island Girl New Users 4 December 8th 07 06:40 PM
Assigning shortcut key to macro jille Microsoft Word Help 1 March 9th 07 07:21 PM
Programatically assigning values to table cells knight06 Microsoft Word Help 2 January 18th 07 04:18 PM
Assigning Color Dmitry Osipov Mailmerge 1 March 20th 06 07:45 PM
assigning a macro macring Microsoft Word Help 1 November 12th 05 07:27 PM


All times are GMT +1. The time now is 02:56 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"