Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Error 91: Object Variable not set

Tags:

vba

outlook

I have the code below to read the table from outlook email. But I'm getting error at the line ActiveInspector.WordEditor.

    Set doc = ActiveInspector.WordEditor
    Set tbl = doc.Tables(1)
    lngRows = tbl.Rows.Count
    lngColumns = tbl.Columns.Count

I've marked the Microsoft Word 12.0 Object Library in the references as well. Can someone help?

I'm trying to solve the problem I mentioned here:

Read a table in outlook mail using macro

like image 592
Pramod Avatar asked Dec 09 '25 05:12

Pramod


1 Answers

If you are using ActiveExplorer.Selection.Item(1) change to either starting with an open mailitem or

Sub inspWord()

    Dim doc As Word.Document
    Dim tbl As Word.Table

    Dim lngRows As Long
    Dim lngColumns As Long

    ActiveExplorer.Selection.Item(1).Display
    Set doc = ActiveInspector.WordEditor
    Set tbl = doc.Tables(1)
    lngRows = tbl.Rows.count
    lngColumns = tbl.Columns.count

End Sub
like image 195
niton Avatar answered Dec 11 '25 11:12

niton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!