0% found this document useful (0 votes)
12 views2 pages

Runtimev 16

The document contains a VBScript that automates reporting in MS-Excel based on a specified Excel sheet. It checks if an Excel application is running and either connects to an existing workbook or opens a new one to input data such as temperature, pressure, and flow. After updating the workbook, it saves and closes the application, ensuring efficient data handling.

Uploaded by

mayank.gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Runtimev 16

The document contains a VBScript that automates reporting in MS-Excel based on a specified Excel sheet. It checks if an Excel application is running and either connects to an existing workbook or opens a new one to input data such as temperature, pressure, and flow. After updating the workbook, it saves and closes the application, ensuring efficient data handling.

Uploaded by

mayank.gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

'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

You might also like