View Single Post
  #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.