'Tested OK VBScript for reporting in MS-Excel as per client submitted EXCEL sheet
Dim wsh, XLSrunning, TargetBookrunning, objExcelApp, objWorkbook, TheTargetBook
Dim TheCount, theSheet, theCell, theLastCell, theLastRow, PreviousDate
Dim objFSO
Dim Date1
Dim EXCEL_R
Const OverwriteExisting = 1
Set wsh = CreateObject("WScript.Shell")
TheTargetBook = "C:\REPORT\samplereport.xlsx"
TheCount = GetObject("winmgmts:root\CIMV2").ExecQuery("SELECT * FROM Win32_Process
WHERE Name='EXCEL.EXE'").Count
'While TheCount is bigger than 0, it means the Excel Application is running..., but
doesn't mean the workbook is open for sure!
If TheCount > 0 Then
Set objExcelApp = GetObject(,"Excel.Application")
' Using GetObject(,"Excel.Application") to point to the running
Excel Application.
TargetBookrunning = 0
For Each XLSrunning In objExcelApp.Workbooks
If XLSrunning.name = TheTargetBook Then'Name Then
TargetBookrunning = 1
End If
Next
If TargetBookrunning = 1 Then
Set objWorkbook = GetObject(TheTargetBook)
Else
Set objWorkbook = objExcelApp.Workbooks.Open(TheTargetBook)
End If
Else
Set objExcelApp = CreateObject("Excel.Application")
Set objWorkbook = objExcelApp.Workbooks.Open(TheTargetBook)
objWorkbook.Worksheets(1).Activate
Set theSheet = objWorkbook.ActiveSheet
End If
objExcelApp.Visible = False
objExcelApp.ScreenUpdating = False
objExcelApp.DisplayAlerts = False
If SmartTags("Excel_row") < 6 Then
SmartTags("Excel_row") = 6
End If
objWorkbook.Worksheets(1).Activate
Set theSheet = objWorkbook.ActiveSheet
With theSheet
.cells(SmartTags("Excel_row"),2) = Now
.cells(SmartTags("Excel_row"),3) = SmartTags("Temperature")
.cells(SmartTags("Excel_row"),4) = SmartTags("Pressure")
.cells(SmartTags("Excel_row"),5) = SmartTags("Flow")
End With
SmartTags("Excel_row") = SmartTags("Excel_row") + 1
objWorkbook.Save
objWorkbook.Close
Set objWorkbook = Nothing
objExcelApp.Quit
Set objExcelApp = Nothing
Set wsh = Nothing