0

I'm trying to loop through selected tables, rows, columns, and cells.
However, I cant get the Table object to set properly into the variable in the for loop.
I inspected the element TypeName(objSel.Tables.Item(1) to validate that the type IS of type Table. But I keep getting a "Type Missmatch" error.

Below, you can see the code and the error. enter image description here

Second Attempt: enter image description here

8
  • Is this in word or outlook? Why if instead of the selection just use the activedocument? Commented Dec 11, 2015 at 17:29
  • What is the type of objSel.Tables? it may be incompatible with the for each verb, if it does not implement an iterator for instance. Commented Dec 11, 2015 at 18:02
  • This is in outlook, but I've imported the Word References. I don't want to modify all tables in the document, just the one i have selected.
    – ScrappyDev
    Commented Dec 11, 2015 at 18:03
  • When I inspect the element it just says "Tables". How would I find out if it has an iterator. (I'm relatively inexperienced w/ VB scripting). Note when i do *.Tables. the options are: Add, Application, Count, Creator, Item, Nesting Level, Parent
    – ScrappyDev
    Commented Dec 11, 2015 at 18:05
  • There's something fishy with your usage of the inspector - make sure it's all syntactically correct from application to application. Commented Dec 11, 2015 at 18:24

1 Answer 1

2

It loods like the issue was because it was trying to store a Word.Table into an Outlook.Table.

Before (Not Working):

Dim aTbl As Table
Dim i As Integer
For i = 1 To objSel.Tables.Count()
    Debug.Print (TypeName(objSel.Tables.Item(i)))
    Set aTbl = objSel.Tables.Item(i)
    Debug.Print (TypeName(aTbl))
Next

After (working):

Dim aTbl As Word.Table
Dim i As Integer
For i = 1 To objSel.Tables.Count()
    Debug.Print (TypeName(objSel.Tables.Item(i)))
    Set aTbl = objSel.Tables.Item(i)
    Debug.Print (TypeName(aTbl))
Next

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .