我正在尝试创建一个 VB 脚本,该脚本搜索一列日期并返回带有今天日期的单元格地址。出于某种原因,我不断收到“需要对象:'FoundCell'”错误。有人可以看看我的代码并纠正我吗?我可以使用 WScript.Echo 读出日期,但是一旦我在 find 函数中使用它,它就会立即给我错误。
Set oExcel = CreateObject("Excel.Application")
Set wshShell = CreateObject("Wscript.Shell")
File_Path = "D:\Work\Personal Timemanagement\test.xlsx"
Set oData = oExcel.Workbooks.Open(File_Path)
WHAT_TO_FIND = Date()
WScript.Echo WHAT_TO_FIND
Set FoundCell = oData.Worksheets("tst2").Range("A1:A40").Find(WHAT_TO_FIND)
oExcel.Cells(4,4) = FoundCell.Address
oExcel.ActiveWorkbook.SaveAs "D:\Work\Personal Timemanagement\test2.xlsx"
oExcel.ActiveWorkbook.Close
oExcel.Application.Quit
WScript.Quit
谢谢您的帮助!