以下是引用leal在2007-12-8 16:21:35的发言:。。。。。。 '如何做到这样的效果,就是如何用WS直接先判断文件是否存在,而不用弹出系统对话框? 不好意思,帖太多,没看到,今天看到了回复,希望不算晚! Set objXL = Wscript.CreateObject("Excel.Application") a = RUNFILE Set objXL = Nothing Function RUNFILE() If FilePath = vbNullString Then Exit Function objXL.Workbooks.Open FilePath objXL.Visible = True 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, 24), "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 |