Here is a stripped-down version of the code I'm trying to run. Note that the type mismatch error is raised on different lines, depending on whether ss is Dim'ed with brackets or not. The error occurs regardless. (By the way, thanks to everyone for taking
an interest.)
' Script: weather.vbs
' Usage: weather.vbs /Folder:<datafolder>
' Process command line arguments
numArgs = WScript.Arguments.Count
Set namedArgs = WScript.Arguments.Named
If Not namedArgs.Exists("Folder") Or numArgs <> 1 Then
WScript.Echo "Usage: weather.vbs /Folder:<foldername>"
WScript.Quit
End If
' Get the folder object
folderName = namedArgs.Item("Folder")
Set fileSystem = CreateObject("Scripting.FileSystemObject")
If fileSystem.FolderExists(folderName) Then
Set folder = fileSystem.GetFolder(folderName)
Else
WScript.Echo "Folder does not exist"
WScript.Quit
End If
' Launch Excel
Set excel = CreateObject("Excel.Application")
excel.DisplayAlerts = False
excel.Visible = True
' Perform calculations on each file in the folder
Set files = folder.Files
For Each file in files
WScript.Echo file.Name
With excel
.Workbooks.OpenText(file.Path)
Call Calc(excel)
.ActiveWorkbook.Save
.Workbooks.Close
End With
Next
excel.Quit
' Calculations
Sub Calc(app)
Dim ss
app.Range("A25204:K29952").Delete
' Copy spreadsheet to array
' type mismatch happens on the following line if Dim ss() or Dim ss(25202,10)
ss = app.Range("A1:K25203").Value
For i = 1 To 25202
'type mismatch happens on the following line if Dim ss
If ss(i, 1) = 1 Then
ss(i, 3) = ss(i, 3) - 1.234
ss(i, 4) = ss(i, 4) - 1.314
ss(i, 6) = ss(i, 6) * 0.984
ss(i, 9) = 0.0
End If
Next
' Copy modified array back to spreadsheet
app.Range("A1:K25203").Value = ss
End Sub