首页 > 解决方案 > Outlook VBA VLOOKUP 转换为 Excel 文件

问题描述

Outlook VBA 的新手如果我希望 Outlook 在 Excel 文件的 A 列中查找值并返回 B 列值,我有哪些选择?(与 VLOOKUP 相同)

Option Explicit

Sub LookUpExcel()

Dim objExcel As New Excel.Application
Dim exWb As Excel.Workbook
Dim ExcelFileName As String
Dim ColumnA As String
Dim ColumnB As String

Dim oMsg As MailItem

ExcelFileName = "C:\Users\vfdme\Desktop\test.xlsx"

Set exWb = objExcel.Workbooks.Open(ExcelFileName)

ColumnA = InputBox("Please Column A value.") 



'[VLOOKUP / Search function?]



MsgBox (ColumnB)

ExitRoutine:
    Set oMsg = Nothing
    Set exWb = Nothing
    Set objExcel = Nothing

End Sub

标签: vbasearchoutlookvlookup

解决方案


让代码正常工作:) 感谢@braX 的提示。

Sub LookUpExcel()

Dim objExcel As New Excel.Application
Dim exWb As Excel.Workbook
Dim ExcelFileName As String
Dim ColumnA As String
Dim ColumnB As String

Dim oMsg As MailItem

ExcelFileName = "C:\Filelocation\Testfile.xlsx"

Set exWb = objExcel.Workbooks.Add(ExcelFileName)


ColumnA = InputBox("Please Column A value.")

ColumnB = exWb.Worksheets("Sheet1").Range("A:A").Find(ColumnA).Offset(0, 1).Value

msgbox (ColumnB)

ExitRoutine:
    Set oMsg = Nothing
    Set exWb = Nothing
    Set objExcel = Nothing

End Sub

推荐阅读