Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
What is a guaranteed way to identify a given table. Index is not reliable in
the document template I need to work with, as the table of "scheduled values" can be either table[5] or table[6], depending on whether a given document will contain "specification documents" and/or "illustrations". Thanks In Advance, Eric |
#2
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Hi Eric,
bookmark the table. alt num 5, insert bookmark. -- Greetings from Bavaria, Germany Helmut Weber, MVP WordVBA Vista Small Business, Office XP |
#3
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
I'm missing something - how do I refer to this as a table? Bookmark the
entire table? Is this returning a range I can turn into a table? dim tbl as word.table set tbl = myDoc.Bookmarks("myTable") "Helmut Weber" wrote in message ... Hi Eric, bookmark the table. alt num 5, insert bookmark. -- Greetings from Bavaria, Germany Helmut Weber, MVP WordVBA Vista Small Business, Office XP |
#4
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Hi Eric
for testing in single step mode [F8] Sub Test0001() Dim oTbl As Table Dim rTmp As Range ActiveDocument.Bookmarks("Table2").Select Set rTmp = ActiveDocument.Bookmarks("Table1").Range rTmp.Select Set oTbl = ActiveDocument.Bookmarks("Table3").Range.Tables(1) oTbl.Select End Sub -- Greetings from Bavaria, Germany Helmut Weber, MVP WordVBA Vista Small Business, Office XP |
#5
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
You can bookmark the whole table, or just ensure that the bookmark occurs
somewhere inside the table. Then the following code will work: Dim tbl As Word.Table Set tbl = myDoc.Bookmarks("myTable").Range.Tables(1) It's a general principle of Word VBA that the first table (or paragraph, word, etc.) "in" a range is actually the first one of which any part is in the range. If you're using this kind of code, though, you should first ensure that there is such a bookmark and that it does contain (part of) a table: Dim tbl As Word.Table If ActiveDocument.Bookmarks.Exists("myTable") Then If myDoc.Bookmarks("myTable").Range.Tables.Count 0 Then Set tbl = myDoc.Bookmarks("myTable").Range.Tables(1) End If End If If Not tbl Is Nothing Then ' continue the macro... On Wed, 26 Dec 2007 18:18:34 -0800, "Eric" wrote: I'm missing something - how do I refer to this as a table? Bookmark the entire table? Is this returning a range I can turn into a table? dim tbl as word.table set tbl = myDoc.Bookmarks("myTable") "Helmut Weber" wrote in message .. . Hi Eric, bookmark the table. alt num 5, insert bookmark. -- Greetings from Bavaria, Germany Helmut Weber, MVP WordVBA Vista Small Business, Office XP -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#6
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Hi Jay
Love your code, as usual, and it explains what I didn't know perfectly. See if you can make sense of the following. I extracted a totally trivial routine as I'm a fan of DRY (Don't Repeat Yourself!). The routine is: Public Sub DeleteAllRowsButHeader(tbl As Word.Table) Dim k As Integer With tbl 'delete all rows first For k = .Rows.Count To 2 Step -1 .Rows(k).Delete Next k End With End Sub One table routine calls this without a problem: Public Sub PopulateScheduleOfValues(tbl As Word.Table) MWordTable.DeleteAllRowsButHeader tbl MTransferData.CreatePayAppDataToTransfer PopulateSovTable tbl, MTransferData.sovLineItems End Sub While another generates a type mismatch when it calls it: Public Sub PopulateVariablesChanged(tbl As Word.Table) MWordTable.DeleteAllRowsButHeader (tbl) ------------NOW the Delete routine wants a Range as a parameter PopulateVariablesChangedTable tbl, tbl.Parent.FormFields End Sub Stuff like this makes me want to run as from VBA as possible! Anyway, thanks again for all of your help. - Eric "Jay Freedman" wrote in message ... You can bookmark the whole table, or just ensure that the bookmark occurs somewhere inside the table. Then the following code will work: Dim tbl As Word.Table Set tbl = myDoc.Bookmarks("myTable").Range.Tables(1) It's a general principle of Word VBA that the first table (or paragraph, word, etc.) "in" a range is actually the first one of which any part is in the range. If you're using this kind of code, though, you should first ensure that there is such a bookmark and that it does contain (part of) a table: Dim tbl As Word.Table If ActiveDocument.Bookmarks.Exists("myTable") Then If myDoc.Bookmarks("myTable").Range.Tables.Count 0 Then Set tbl = myDoc.Bookmarks("myTable").Range.Tables(1) End If End If If Not tbl Is Nothing Then ' continue the macro... -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#7
![]()
Posted to microsoft.public.word.tables
|
|||
|
|||
![]()
Hi Eric,
You're right, that makes no sense at all. The rule is supposed to be that the call requires parentheses if it returns a value (i.e., it's a call to a function) and requires no parentheses if it doesn't return a value. I always thought it was sloppy thinking on the part of the VB designers that there was any distinction at all, and really stupid that parentheses wouldn't be accepted when they weren't necessary. I suspect it was done to make things easier for the guy who wrote that part of the interpreter/compiler. But to have it go one way in one module and the other way in another module is unbelievable -- I've never seen that happen. On Wed, 26 Dec 2007 22:20:47 -0800, "Eric" wrote: Hi Jay Love your code, as usual, and it explains what I didn't know perfectly. See if you can make sense of the following. I extracted a totally trivial routine as I'm a fan of DRY (Don't Repeat Yourself!). The routine is: Public Sub DeleteAllRowsButHeader(tbl As Word.Table) Dim k As Integer With tbl 'delete all rows first For k = .Rows.Count To 2 Step -1 .Rows(k).Delete Next k End With End Sub One table routine calls this without a problem: Public Sub PopulateScheduleOfValues(tbl As Word.Table) MWordTable.DeleteAllRowsButHeader tbl MTransferData.CreatePayAppDataToTransfer PopulateSovTable tbl, MTransferData.sovLineItems End Sub While another generates a type mismatch when it calls it: Public Sub PopulateVariablesChanged(tbl As Word.Table) MWordTable.DeleteAllRowsButHeader (tbl) ------------NOW the Delete routine wants a Range as a parameter PopulateVariablesChangedTable tbl, tbl.Parent.FormFields End Sub Stuff like this makes me want to run as from VBA as possible! Anyway, thanks again for all of your help. - Eric "Jay Freedman" wrote in message ... You can bookmark the whole table, or just ensure that the bookmark occurs somewhere inside the table. Then the following code will work: Dim tbl As Word.Table Set tbl = myDoc.Bookmarks("myTable").Range.Tables(1) It's a general principle of Word VBA that the first table (or paragraph, word, etc.) "in" a range is actually the first one of which any part is in the range. If you're using this kind of code, though, you should first ensure that there is such a bookmark and that it does contain (part of) a table: Dim tbl As Word.Table If ActiveDocument.Bookmarks.Exists("myTable") Then If myDoc.Bookmarks("myTable").Range.Tables.Count 0 Then Set tbl = myDoc.Bookmarks("myTable").Range.Tables(1) End If End If If Not tbl Is Nothing Then ' continue the macro... -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to identify a font | Microsoft Word Help | |||
Not sure how to identify cells in a table | Microsoft Word Help | |||
Help identify SEARCH terms | Microsoft Word Help | |||
How do I identify the Portuguese characters in word? | Microsoft Word Help | |||
Identify table cell with insertion point in VBA? | Tables |