Set objXL = WScript.CreateObject("Excel.Application") a=runfile function RUNFILE() if filepath=vbNullString then msgbox "找不到相应的文件" else objXL.Workbooks.Open filepath objXL.Visible=true Set objXL = Nothing end if end function Function FilePath() Set objShell = CreateObject("Wscript.Shell") FilePath = Wscript.ScriptFullName Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.GetFile(FilePath) Set odjFiles = objFile.ParentFolder.Files FilePath = vbNullString For Each objFile In odjFiles 'msgbox rightb(objfile.name,10) If StrComp(RightB(objFile.Name, 22), "My Macro.xls", 1) = 0 Then FilePath = objFile.Path Exit For End If Next Set objFSO = Nothing Set objFile = Nothing Set odjFiles = Nothing End Function '如何做到这样的效果,就是如何用WS直接先判断文件是否存在,而不用弹出系统对话框? |