我有一个Word VBA宏,可以很好地填充Excel工作簿(充当'数据库')的数据。它称为excel索引和匹配函数。但是,截至今天,我一再收到错误,告诉我找不到匹配和索引功能。发生了什么?代码如下。
On Error Resume Next
Set xlapp = GetObject(, "Excel.Application")
If Err Then
bStart = True
Set xlapp = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set xldocbook = xlapp.Workbooks.Open("D:/Dr list.xlsx")
Set xldocsheet = xldocbook.Worksheets(1)
'Set the current selection
With xlapp.WorksheetFunction
IUH = .Index(xldocsheet.Range("I:I"), .Match(DrName, xldocsheet.Range("E:E"), 0))
If IUH = "N" Then
Address = .Index(xldocsheet.Range("K:K"), .Match(DrName, xldocsheet.Range("E:E"), 0))
CityStateZip = .Index(xldocsheet.Range("L:L"), .Match(DrName, xldocsheet.Range("E:E"), 0))
Else
Address = ""
CityStateZip = ""
End If
Phone = .Index(xldocsheet.Range("F:F"), .Match(DrName, xldocsheet.Range("E:E"), 0))
Fax = .Index(xldocsheet.Range("G:G"), .Match(DrName, xldocsheet.Range("E:E"), 0))
FullAddress = Address + " " + CityStateZip
Debug.Print "Full Address is" + FullAddress
End With
xldocbook.Close
If bStart = True Then
xlapp.Quit
End If