如何在Excel工作表中查找确切值

mhs*_*mhs 5 vbscript

如何在Excel工作表中找到字符串值。我正在尝试,objRange.Find()但这也给我错误的地址。作为示例,我想要'Object_paint'的地址,但它也提供了'Object_paint_and_stk'的地址。

我应该只获得确切的价值吗?

Set objWorksheet = objWorkbook.Worksheets(worksheet)
Set objRange = objWorksheet.Range("B2:B600")    
Set objFind = objRange.Find("object_paint")

If Not objFind Is Nothing Then
    searchValue = objFind.AddressLocal(False, False)
end if
Run Code Online (Sandbox Code Playgroud)

Ekk*_*ner 4

第一击为

excel range.find exact match site:microsoft.com
Run Code Online (Sandbox Code Playgroud)

是:

范围查找

在那里你会发现

查看类型:System.Object

Optional Object. Can be one of the following XlLookAt constants: xlWhole or xlPart.
Run Code Online (Sandbox Code Playgroud)

并点击LookAt 链接,您会看到:

xlPart  Match against any part of the search text.
xlWhole Match against the whole of the search text.
Run Code Online (Sandbox Code Playgroud)

顺便说一句:objTarget 是谁?

更新:

您必须将您在评论中提到的 VBA 代码片段“移植”(此处有一些提示)到 VBScript:

Option Explicit

' Define Excel Consts unknown to VBScript
Const xlPart  = 2 
Const xlWhole = 1 

Dim oExcel : Set oExcel = CreateObject("Excel.Application")
Dim oWBook : Set oWBook = oExcel.Workbooks.Open("M:\lib\kurs0705\testdata\ut.xls")
Dim oRange : Set oRange = oWBook.Sheets("NewSheet").Range("A1:A11")
' translate named args to positional args
' expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte)
Dim oFnd1  : Set oFnd1  = oRange.Find("Title1", , , xlPart)
WScript.Echo TypeName(oFnd1), CStr(oFnd1)
Dim oFnd2  : Set oFnd2  = oRange.Find("Title1", , , xlWhole)
WScript.Echo TypeName(oFnd2), CStr(oFnd2)

oWBook.Close
oExcel.Quit
Run Code Online (Sandbox Code Playgroud)

输出:

cscript excelfind.vbs
Range Title10
Range Title1
Run Code Online (Sandbox Code Playgroud)