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.