VBA错误91:未设置对象变量

时间:2016-07-08 22:19:12

标签: outlook-vba

我有以下代码来阅读outlook电子邮件中的表格。但我在第ActiveInspector.WordEditor行收到错误。

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

我也在参考文献中标记了Microsoft Word 12.0 Object Library。有人可以帮忙吗?

我试图解决我在这里提到的问题:

Read a table in outlook mail using macro

1 个答案:

答案 0 :(得分:1)

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