![]() |
#1
|
|||
|
|||
![]()
Hi there!
I have a basic macro that changes table properties (lines, width, etc.) of the first FOUR tables found in the document which form a masthead (see below) It works great... but what about document not having the masthead, the macro will still run and mess up the four first tables found in the document. I am using to Selection.Information(wdActiveEndPageNumber) to check that that tables are in page 1 However, I wonder if there is any better option. I saw "ID" under "Table", can table be given an unique ID or name? Or any identifier? Thanks |
#2
|
||||
|
||||
![]()
It is probably best to error trap each table to ensure that you are processing the correct tables e.g. as follows. I have assumed each table has six cells - change each as appropriate. However why do you need to change the tables? Wouldn't it be better to create your document from a template that already has the masthead correctly formatted?
Code:
Dim oTable As Table Dim i As Integer If ActiveDocument.Tables.Count > 3 Then If ActiveDocument.Tables(1).Range.Cells.Count = 6 And _ ActiveDocument.Tables(2).Range.Cells.Count = 6 And _ ActiveDocument.Tables(3).Range.Cells.Count = 6 And _ ActiveDocument.Tables(4).Range.Cells.Count = 6 And _ ActiveDocument.Tables(4).Range.Information(wdActiveEndPageNumber) = 1 Then For i = 1 To 4 Set oTable = ActiveDocument.Tables(i) 'Do something with otable e.g. oTable.Cell(1, 1).Range.Text = "Test" Next i End If End If
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
Thanks Gmayor for your reply.
Sure, I will have to error trap each tables. Counting cells is a possibility... however, since the last table has a bookmark, I am thinking about selecting tables 1 to 4 as range and check if bookmark is there. Why not creating a straightforward template? Indeed. We get document from our clients so the macros we have are macros that will reset default - default masthead + default pagesetup + default stylesheet... while doing the default settings, macro will check for the type of document (category properties) and will load the few specificities. I hope it is understable. Since most of our templates follow the default one, I decided to have macros (instead of hundreds of templates) and just a few templates on the side for the specific ones. Thanks |
#4
|
||||
|
||||
![]()
If there's a bookmark in table 4, the code can be simplified e.g as below, where I have also provided different options for each of the four tables if required.
Code:
If ActiveDocument.Tables.Count > 3 Then If ActiveDocument.Tables(4).Range.Bookmarks.Exists("bmName") = True Then For i = 1 To 4 Set oTable = ActiveDocument.Tables(i) 'Do something with otable e.g. Select Case i Case Is = 1 oTable.Cell(1, 1).Range.Text = "Test" Case Is = 2 oTable.Cell(1, 1).Range.Text = "Test2" Case Is = 3 oTable.Cell(1, 1).Range.Text = "Test3" Case Is = 4 oTable.Cell(1, 1).Range.Text = "Test4" End Select Next i End If End If
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
![]()
Thanks Graham for the code and answer.
As a general question, there is no way to have unique identifier to objects then? A bit like ID in HTML which is a unique ID for elements... Odd. |
#6
|
||||
|
||||
![]()
Activedocument.Tables(1) is uniquely the first table.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#7
|
||||
|
||||
![]()
There is a Table.ID property but the help says it only works if the document is saved as html.
You can use Table.Title or Table.Descr to see the values entered via Table Properties > Alt Text dialog. This is usually how I identify particular tables.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
|||
|
|||
![]()
Thanks Guessed and gmayor.
The Table.Title is a nice way around and does work. However, after consideration, since I need to parse the table to do stuff, I have opted for gmayor option which is to verify conformity of the table (check cells). I will mark it as solved. Thanks |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Looking for a macro for word count in one specific column of table, only rows with white background | mobj | Word VBA | 2 | 10-17-2019 03:09 AM |
![]() |
JellehFishh | Word VBA | 2 | 06-27-2019 08:23 AM |
Linking Specific text fields in PP to specific cells in an Excel table | GWRW1964 | PowerPoint | 0 | 02-26-2018 07:37 AM |
![]() |
jc491 | Word VBA | 8 | 09-30-2015 06:10 AM |
![]() |
Lebber | Word | 9 | 02-01-2013 12:31 AM |