0

我试图提示用户输入,然后从 Excel 报告中查找该信息。并填充 Word 文档,但我不确定错误在哪里。我试图基于这个问题这个问题的代码。

它给了我运行时错误“438” 对象不支持此属性或方法。我知道这是我使用该方法的方式,请您指出正确的方向吗?谢谢!

Sub PopulateForm()
    Dim objExcel As New Excel.Application
    Dim exWb As Excel.Workbook
    Dim cin_number As String
    Dim result As String

    ' Prompt user for input
    cin_number = InputBox("Please enter the CIN#", "Input")

    ' Open the cover sheet letter
    Set exWb = objExcel.Workbooks.Open("U:\HRA Cover Sheet Data.xls")

    ' Perform the VLookup...
    result = objExcel.WorksheetFunction.VLookup(cin_number, _
        exWb.Range("A:F"), 5, False)

    ' Testing the output
    MsgBox result

    exWb.Close

    Set exWb = Nothing
End Sub

我正在使用 Word 2003 和 Window XP。

4

1 回答 1

1

您正在尝试获取exWb一个工作簿而不是工作表的范围。尝试

result = objExcel.WorksheetFunction.VLookup(cin_number, _
    exWb.ActiveSheet.Range("A:F"), 5, False)
于 2014-06-18T21:02:34.207 回答