Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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
Posted to microsoft.public.word.tables
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Assigning shortcut keys | New Users | |||
Assigning shortcut key to macro | Microsoft Word Help | |||
Programatically assigning values to table cells | Microsoft Word Help | |||
Assigning Color | Mailmerge | |||
assigning a macro | Microsoft Word Help |