简体   繁体   English

在Excel中使用VLookup的运行时错误

[英]Runtime error using VLookup with Excel

I keep getting: 我不断得到:

a Run-time error '1004' Unable to get the Vlookup property of the WorksheetFunction class 运行时错误“ 1004”无法获取WorksheetFunction类的Vlookup属性

with the Vlookup code below. 使用下面的Vlookup代码。

If I enable Microsoft outlook 12.0 Object Library it works but I run into issues where the code is used with Excel 2013 and adds Microsoft outlook 15.0 Object Library references that are not available on excel 2007. I have incorporated late binding which has worked for the most part except for this one bit of code. 如果启用了Microsoft outlook 12.0 Object Library则可以使用,但是我遇到了将代码与Excel 2013一起使用的问题,并添加了Excel 2007中不可用的Microsoft outlook 15.0 Object Library引用。这部分代码除外。

I have included a snippet of code which I hope is enough for someone to help me. 我提供了一段代码,希望对某人有所帮助。

Sub Button154_Click()

    Dim forename As String
    Dim surname As String
    Dim movedate As String
    Dim callref As String
    Dim dept As String
    Dim deptmove As String
    Dim wb As Workbook

    Set wb = ThisWorkbook

    forename = Sheet1.Range("f8").Value
    surname = Sheet1.Range("f9").Value
    movedate = Sheet1.Range("k13").Value
    callref = Sheet1.Range("k8").Value
    dept = Application.WorksheetFunction.VLookup(Name, Sheet1.Range("K10"), 1)

Added late binding code Dim otlApp As Object Set otlApp = CreateObject("Outlook.Application") 添加了后期绑定代码Dim otlApp作为对象集otlApp = CreateObject(“ Outlook.Application”)

An changed the vlookup to: dept = Application.WorksheetFunction.VLookup(oltApp, Sheet1.Range("K10"), 1) 将vlookup更改为:dept = Application.WorksheetFunction.VLookup(oltApp,Sheet1.Range(“ K10”),1)

Now works great 现在效果很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM