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"
3. 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
4. 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 = NothingClose 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.
