我只想测试对象是否已设置。对我来说似乎很简单。
Option Explicit
Dim objExcel, wMn
Set objExcel = CreateObject("Excel.Application")
msgbox "test"
On Error Resume Next
Set wMn = objExcel.Workbooks.Open("Z:\path\file_*.xlsm")
msgbox "test1"
If Err.Number = 0 then
msgbox "test2"
end if
On Error Goto 0
msgbox"测试"显示,但msgbox" test1"和msgbox" test2"永远不会显示如果文件不存在,我只是挂在Set上。 VBS只是请。感谢。
我知道我可以使用文件系统对象,但我想知道为什么我不能做这样的事情。
答案 0 :(得分:0)
看起来Excel在Open方法中不支持通配符。
Option Explicit
Dim objExcel, wMn
Set objExcel = CreateObject("Excel.Application")
MsgBox "test"
objExcel.Visible = True 'Otherwise you'll never see it
On Error Resume Next
Set wMn = objExcel.Workbooks.Open("C:\path\actualfile.xls") 'Works
'Set wMn = objExcel.Workbooks.Open("C:\path\actualfil*.xls") 'Won't work even if only file that could match wild card
MsgBox "test1"
If Err.Number = 0 Then
MsgBox "test2"
Else
'Output error to help you work out what wrong...
MsgBox "Err:" & Err.Description
End If
On Error Goto 0