引用excel VBA中的单词表?

我正在尝试编写一个excelmacros来打开一个rtf文档,并根据几个variables(pulldate和rmname)返回特定表的页码。 下面的代码在Word VBA中完美地工作(当然,使用“activedocument”来代替“wdApp”),但是当我尝试从excel中实现时,它会中断。

Sub find_pulls() Dim wdApp As Object Dim pullsheets As Object Dim totalPullPages As Integer Dim pg As Pages Dim start As String Dim finish As String Dim rmname As String Dim tnumber As Integer Dim pSnumber As String Dim pEnumber As String Dim pulldate As String Set wdApp = CreateObject("word.application") Set pullsheets = wdApp.documents.Open _ ("C:\Users\xxxxx\xxxxxxxx\xxxxx\pullsheets.rtf") wdApp.visible = True pulldate = "05/06/2017" rmname = "503" For Each cell In wdApp.ActiveDocument.Tables If InStr(cell, rmname) > 0 Then cell.Select If Left(wdApp.Selection.Cells(5).Range.Text, 10) = pulldate Then tnumber = wdApp.ActiveDocument.Range(0, wdApp.Selection.Tables(1).Range.End).Tables.Count Debug.Print tnumber Set t = wdApp.ActiveDocument.Tables(tnumber) pSnumber = t.Range.Information(wdActiveEndPageNumber) Set t = wdApp.ActiveDocument.Tables(tnumber + 1) pEnumber = t.Range.Information(wdActiveEndPageNumber) Debug.Print "Pull is pg." & pSnumber & "-" & pEnumber End If End If Next cell wdApp.Quit SaveChanges:=wdDoNotSaveChanges End Sub 

我在“pSnumber = …”行得到“超出范围”的值。 我假设这是因为在Excel中没有任何表格对象,因为有字 – 是否有任何解决方法来获得我正在寻找的值?

我们的目标是search文档(它总是以两个表格集合,一个是标题信息,另一个是紧跟在行项目之后),并返回find的表格的结束页码。 这些值将被用于复制表格数据或打印这些页面。 Pulldate和rmname将最终成为基于用户input的variables。 没有选项直接在word中运行macros,因为.rtf文件是系统生成的,必须通过主excel表访问。

有任何想法吗?