【发布时间】:2021-06-14 07:40:59
【问题描述】:
我有一个 VBA 代码,它可以在 excel 列中返回特定日期的单元格地址。
VBA 代码:-
Sub GetDates2()
Const findDate As Date = #10/1/2020#
Dim R As Range, C As Range, WS As Worksheet
Set WS = Worksheets("FY2021 Bank txn-stats")
Set R = WS.UsedRange
For Each C In R
If C.Value2 = CDbl(findDate) Then MsgBox (findDate & " found in " & C.Address)
Next C
End Sub
现在我想要一个与上面的 VBA 代码相对应的 VBScript 代码,我应该能够在其中提供要查找的 excel 文件位置和日期。
我自己试过了,但没有输出。
VBScript 代码(我试过):-
Sub GetDates2()
Dim R,C,WS,findDate
Set findDate=#10/01/2020#
Set oExcel = CreateObject("Excel.Application")
Set oData = oExcel.Workbooks.Open(FileLocation)
Set WS = oData.Worksheets("FY2021 Bank txn-stats")
Set R = WS.Range("C1:C500").Cells
For Each C In R
If C.Value = CDbl(findDate) Then MsgBox (findDate & " found in " & C.Address)
Next
End Sub
请帮帮我。
【问题讨论】:
-
Set用于对象引用,findDate不是对象引用,删除Set。