Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Eric[_2_] Eric[_2_] is offline
external usenet poster
 
Posts: 8
Default how to identify a given table

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   Report Post  
Posted to microsoft.public.word.tables
Helmut Weber[_2_] Helmut Weber[_2_] is offline
external usenet poster
 
Posts: 45
Default how to identify a given table

Hi Eric,

bookmark the table.
alt num 5, insert bookmark.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
  #3   Report Post  
Posted to microsoft.public.word.tables
Eric[_2_] Eric[_2_] is offline
external usenet poster
 
Posts: 8
Default how to identify a given table

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   Report Post  
Posted to microsoft.public.word.tables
Helmut Weber[_2_] Helmut Weber[_2_] is offline
external usenet poster
 
Posts: 45
Default how to identify a given table

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   Report Post  
Posted to microsoft.public.word.tables
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default how to identify a given table

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   Report Post  
Posted to microsoft.public.word.tables
Eric[_2_] Eric[_2_] is offline
external usenet poster
 
Posts: 8
Default how to identify a given table

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   Report Post  
Posted to microsoft.public.word.tables
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default how to identify a given table

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

Posting Rules

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to identify a font Maurice Microsoft Word Help 1 October 30th 07 05:36 PM
Not sure how to identify cells in a table j_richmo Microsoft Word Help 1 September 15th 06 06:35 PM
Help identify SEARCH terms Dirtbike Microsoft Word Help 0 August 22nd 06 05:41 PM
How do I identify the Portuguese characters in word? RandyB Microsoft Word Help 2 February 23rd 05 01:05 AM
Identify table cell with insertion point in VBA? Ed Tables 5 February 3rd 05 03:23 PM


All times are GMT +1. The time now is 04:00 PM.

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

About Us

"It's about Microsoft Word"