Learning Foundation: Excel Reporting
This page has one defined job in the WinCC VBScript learning path. Master this foundation before using the same concept inside larger SCADA, SQL Server and reporting scripts.
Loops, error handling and a clear source dataset from tags/SQL/CSV. Excel must be installed on the runtime/report PC.
Excel COM automation must create objects in a controlled order, write data efficiently, format only what is needed, save deterministically and release every COM object.
Generate an SQF production report with timestamp, charge, setpoint/actual values and status columns.
Automate Excel.Application safely and avoid orphaned EXCEL.EXE processes through proper save/close/cleanup.
Collect report dataset
Create COM server
Create/open report file
Write and format cells
SaveAs, Close, Quit, Nothing
Complete WinCC VBScript Learning Path
Use Previous/Next for the recommended practical order, or open any topic below as a reference.
Generate Excel Reports from WinCC Using VBScript
This lab targets wincc excel report vbscript with copy-ready examples, expected results and diagnostic guidance.
1. Choose an Excel Automation Architecture
WinCC VBS can automate desktop Excel through COM when Excel is installed on the Runtime station. For unattended or server systems, CSV or a server-side reporting service is often more reliable. Confirm licensing, interactive-session behavior and support requirements.
2. Create a Workbook and Worksheet
Dim excelApp, workbook, worksheet
Set excelApp = CreateObject("Excel.Application")
excelApp.Visible = False
Set workbook = excelApp.Workbooks.Add
Set worksheet = workbook.Worksheets(1)
worksheet.Name = "Process Report"
worksheet.Cells(1, 1).Value = "Timestamp"
worksheet.Cells(1, 2).Value = "Temperature"
worksheet.Cells(1, 3).Value = "Pressure"
Easy TestEasy Test 1 — InputBox + MsgBox
Dialog-first test before launching Excel automation.
Dim ReportName
ReportName = InputBox("Enter report name", "Easy Test 1 — InputBox + MsgBox", "SQF_Process_Report.xlsx")
If ReportName = "" Then
MsgBox "Test cancelled.", vbInformation, "Excel Quick Test"
Else
MsgBox "Excel test value received:" & vbCrLf & ReportName & vbCrLf & _
"Now run the original Excel automation code above.", _
vbInformation, "Excel Quick Test"
End If3. Write WinCC Tag Values
Dim tempTag, pressureTag
Set tempTag = HMIRuntime.Tags("Demo_Temperature")
Set pressureTag = HMIRuntime.Tags("Demo_Pressure")
tempTag.Read
pressureTag.Read
worksheet.Cells(2, 1).Value = Now
worksheet.Cells(2, 2).Value = CDbl(tempTag.Value)
worksheet.Cells(2, 3).Value = CDbl(pressureTag.Value)
worksheet.Columns("A:C").AutoFit
Easy TestEasy Test 2 — InputBox + MsgBox
Dialog-first test before launching Excel automation.
Dim ReportName
ReportName = InputBox("Enter report name", "Easy Test 2 — InputBox + MsgBox", "SQF_Process_Report.xlsx")
If ReportName = "" Then
MsgBox "Test cancelled.", vbInformation, "Excel Quick Test"
Else
MsgBox "Excel test value received:" & vbCrLf & ReportName & vbCrLf & _
"Now run the original Excel automation code above.", _
vbInformation, "Excel Quick Test"
End If4. Save and Clean Up Excel Correctly
Dim reportPath
reportPath = "C:\WinCC_Reports\ProcessReport.xlsx"
workbook.SaveAs reportPath
workbook.Close False
excelApp.Quit
Set worksheet = Nothing
Set workbook = Nothing
Set excelApp = Nothing
Easy TestEasy Test 3 — InputBox + MsgBox
Dialog-first test before launching Excel automation.
Dim ReportName
ReportName = InputBox("Enter report name", "Easy Test 3 — InputBox + MsgBox", "SQF_Process_Report.xlsx")
If ReportName = "" Then
MsgBox "Test cancelled.", vbInformation, "Excel Quick Test"
Else
MsgBox "Excel test value received:" & vbCrLf & ReportName & vbCrLf & _
"Now run the original Excel automation code above.", _
vbInformation, "Excel Quick Test"
End IfClose worksheet/workbook references before quitting Excel. Add scoped error handling and cleanup so a failed save does not leave hidden Excel processes running.
5. Excel Report Troubleshooting
| Problem | Check |
|---|---|
| Cannot create Excel.Application | Excel installation, COM registration, bitness and Runtime identity |
| Workbook cannot save | Folder access, existing locked file and valid extension |
| Excel.exe remains running | Unreleased worksheet/range/workbook references or skipped cleanup |
| Automation fails as a service | Use CSV or a supported server-side report architecture |
Hands-On Verification Lab
Hands-onPrepare a controlled test
Create only the internal tags, folders or disposable database rows required by this tutorial.
Run the smallest example
Execute one operation and inspect WinCC diagnostics before expanding the script.
Test a failure path
Use a safe backup copy to test an invalid tag, path or disposable input.
Frequently Asked Questions
Should this WinCC VBScript be tested in production?
No. Use a backed-up training or staging project and follow the plant change-control process.
Which WinCC versions does the example target?
The examples target classic WinCC Explorer V7.x/V8.x. Verify object properties, action signatures and providers in the installed WinCC help.
How should Runtime failures be diagnosed?
Use scoped Err checks, WinCC object diagnostics and HMIRuntime.Trace while recording the exact station, trigger, tag and Runtime identity.
SQF Running Project Lab · Blog 18
Excel report source
SELECT TOP 100
DT, TM, SQF_No, ChargeNo, Event_From, Event_To,
Temp_Set, Temp_Act, Cp_Set, Cp_Act, Oil_Set, Oil_Act,
Jacket_Set, Jacket_Act, Fan_Status
FROM dbo.tblEvent
ORDER BY ID DESC;
Easy TestEasy Test 4 — InputBox + MsgBox
Read/query preview using the SQF running project.
Dim ChargeNo
ChargeNo = InputBox("Enter a Charge Number to understand this query", "Easy Test 4 — InputBox + MsgBox", "CHG-001")
If ChargeNo = "" Then
MsgBox "Test cancelled.", vbInformation, "Quick Test"
Else
MsgBox "Query input = " & ChargeNo & vbCrLf & _
"Run the SQL above against SQF_DB.dbo.tblEvent to see the actual rows.", _
vbInformation, "SQL Quick Test"
End If