I'm trying to use the VBA code: Application.WorksheetFunction.Average(Range)
'In VBScript, I've declared;
Dim i 'just some counter index for a loop
set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkbooks = xlApp.Workbooks
Set xlWorkbook = xlWorkbooks.Open(ExcelFileToOpen)
Set xlSheet = xlWorkbook.Worksheets(1)
'assuming there is data in a range and I have NumDataColumns of data:
For i = 0 To NumDataColumns - 1
'calc mean value, add to data sheet, add to data array,
'check against limit,
'if exceeds limit, set Notification flag to true and modify
'alarm message
''''''''''''''''''''
'problem here'
''''''''''''''''''''
xlSheet.Cells(lastrow + 1, 4 + i).Value =
xlApp.WorksheetFunction.Average(Range(Cells(11, 4 + i), Cells(lastrow, 4 +
i)))
'this is giving me fits, the interpreter keeps spitting back the error
message:
'Error: Type mismatch: 'Cells'
'Type: 800A000D
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'this is what I'll ultimately do with the data
CalculatedData(i, 1) = xlSheet.Cells(lastrow + 1, 4 + i).Value
If CalculatedData(i, 1) >= AlarmLimits(i, 1) Then
TrippedAlarms(i, 1) = True
Notification = True
AlarmMessage = AlarmMessage & "Average temperature of " &
AlarmLimits(i, 1) & " was exceeded (" & CalculatedData(i, 1) & ")" & Chr(10)
End If
'<snip>
Next
'''''''''''''''''''''''''''
Of course, I've already verified that everything works fine, when I run the
code as VBA from within Excel.
What I'm looking for help on is how in the heck do you access the Excel (or
any Office Application for that matter) methods from VBScript?
xlSheet.Cells(lastrow + 1, 4 + i).Value = _
xlApp.WorksheetFunction.Average(_
xlSheet.Range(xlSheet.Cells(11, 4 + i),_
xlSheet.Cells(lastrow, 4 + i)))
The problem with porting working VBA code to VBScript is that Excel (and other VBA enabled applications) exposes a lot of the app's object model implicitly such that explicit object qualifications aren't strictly needed in VBA code. You don't have that luxury in external automation clients like VBScript or even a VB app that does Office automation.
--
Michael Harris
Microsoft.MVP.Scripting
"gtrager" <gtr...@aviron.com> wrote in message news:#L4ne6DhBHA.2256@tkmsftngp04...
-George
"Michael Harris (MVP)" <mik...@mvps.org> wrote in message
news:#JhIUiEhBHA.2384@tkmsftngp03...