Option Explicit
' File-Attributes enum...
Const Attrib_Normal = 0
Const Attrib_ReadOnly = 1
Const Attrib_Hidden = 2
Const Attrib_System = 4
Const Attrib_Volume = 8
Const Attrib_Directory = 16
Const Attrib_Archive = 32
Const Attrib_Alias = 1024
Const Attrib_Compressed = 2048
Dim objExcelApp
Dim objExcelWb
Dim objFSO
Dim objFolder
Dim objFile
On Error Resume Next
' Open Excel...
Set objExcelApp = WScript.CreateObject(Excel.Application)
If CheckError(err) Then
WScript.Quit(12)
End If
' Open FSO...
Set objFSO = WScript.CreateObject(Scripting.FileSystemObject)
If CheckError(err) Then
WScript.Quit(12)
End If
' iterate thru directory and open the workbooks...
Set objFolder = objFSO.GetFolder(f:\sheets)
If CheckError(err) Then
WScript.Quit(12)
End If
For Each objFile In objFolder.Files
If (LCase(objFSO.GetExtensionName(objFile.Path)) = xls) Or _
(LCase(objFSO.GetExtensionName(objFile.Path)) = xlt) Then
Set objExcelWb = objExcelApp.Workbooks.Open(objFile.Path)
If CheckError(err) Then
WScript.Quit(16)
End If
End If
Next
' Show excel-window...
objExcelApp.Visible = True
Set objFolder = Nothing
Set objFSO = Nothing
WScript.Quit(0)
' End of program...
' -------------------------------------------------------------------------------------------
' Helper-Function
Function CheckError(objError)
If objError.number <> 0 Then
Call MsgBox(WScript.ScriptName & : Error, 0x & Hex(objError.number) &_
occured, & objError.Description)
CheckError = True
Exit Function
End If
CheckError = False
End Function
' -------------------------------------------------------------------------------------------