Exporting WinCC Runtime Data to Microsoft Excel via VBScript
Operators, quality engineers, and shift supervisors frequently need WinCC runtime data outside the HMI process — as a daily shift report, a quality archive, or a regulatory record. Although Siemens ships dedicated archiving solutions, the most flexible path for ad-hoc reports is a VBScript action embedded directly in a WinCC picture, button, or global action. The script drives Microsoft Excel through the COM automation interface, reads live or archived tags through the WinCC object model (HMIRuntime.Tags), and writes formatted values into a workbook.
This reference documents three production-grade methods for moving data out of WinCC into Excel, lists the exact API surfaces used in each, and supplies verified code templates that you can paste into a WinCC V7.5/V8.x project or a TIA Portal WinCC Professional runtime. Configuration paths, Excel object-model references, error handling, performance limits, and an end-to-end verification procedure are included.
1. Integration Options at a Glance
Three mechanisms are available to a WinCC integrator who needs Excel output. The choice depends on report volume, refresh cadence, deployment footprint, and licensing budget.
| Mechanism | Component | Best for | Licensing | Limitations |
|---|---|---|---|---|
| VBScript + Excel COM | WinCC VBScript editor, Microsoft Excel on RT PC | Ad-hoc operator reports, shift logs, small daily exports (< 10,000 rows) | Standard WinCC RT license; Microsoft Excel license on RT PC | Single Excel instance per process; memory pressure at high call rates |
| DataMonitor / PMOPEN EXPORT | SIMATIC WinCC/DataMonitor option package | Scheduled Excel/CSV/PDF reports from TagLogging and AlarmLogging archives | WinCC DataMonitor license (server + client) | Fixed templates; modification requires WebCenter |
| Connectivity Pack / OPC UA / WinCC OLE DB | WinCC Connectivity Station, OPC UA server, or OLE DB provider | Real-time bidirectional data exchange; statistical analysis in Excel via Power Query | WinCC Connectivity Pack license | Higher setup complexity; requires Connectivity Station |
The remainder of this article focuses on the first mechanism — VBScript driving Excel directly — because it requires the fewest license components and is the method most frequently asked about in support escalations. See Section 9 for an architecture overview of the DataMonitor route.
2. Prerequisites
- WinCC Runtime: WinCC V7.4 SP1 or later, or WinCC Professional V16/V17/V18. Older V7.0/V7.2 projects can be migrated; the API surface used here is unchanged back to V7.0.
-
Microsoft Excel: A 32-bit or 64-bit edition installed on the WinCC runtime station. Match the Excel bitness to the WinCC bitness — a 32-bit WinCC process cannot host a 64-bit Excel COM server and will fail with
0x80040154 Class not registered. - DCOM permissions: The user account running the WinCC runtime must be a member of the local Distributed COM Users group, and must have launch and access permissions on the Excel COM application (dcomcnfg.exe → Component Services → Computers → My Computer → DCOM Config → Microsoft Excel Application).
-
File system access: The WinCC runtime user must have Read/Write/Modify on the target folder, for example
C:\WinCCReports\or a UNC path such as\\FS01\Reports\. -
VBScript action container: A button on a WinCC picture, a global action triggered by a tag change, or a scheduled C-action wrapper (the C action calls
ProgramExecute("cscript report.vbs")). -
Optional: Reference workbook. If you are appending rows to an existing template, the
.xlsxor.xlsfile must exist before the script runs.
3. The WinCC VBScript Object Model Used for Excel Export
WinCC exposes a stable COM object tree that VBScript can navigate. The relevant nodes for Excel export are:
| Object | Path | Typical use |
|---|---|---|
HMIRuntime |
Top-level object, always available | Entry point to tags, screens, alarms |
HMIRuntime.Tags |
Tags collection | Read/write tag values with .Read and .Write
|
HMIRuntime.AlarmLogging |
Alarm system | Read archive alarms for export |
HMIRuntime.Logging |
Logging system | Query TagLogging archives |
CreateObject("Excel.Application") |
External COM instantiation | Launch hidden or visible Excel instance |
Tag reads return a HMI Tag object. After objTag.Read, the runtime value is in objTag.Value, the quality code in objTag.Quality, and the timestamp in objTag.Timestamp (UTC). The full object reference is documented in the WinCC V7.5 SP2 manual, function section "VBScript for Creating Procedures and Actions" — see SIMATIC WinCC V7.5 SP2 Manual Collection.
4. Method 1 — Writing Live Tag Values to an Existing Workbook
The classic operator shift report pattern. A pre-built template file (ShiftReport.xlsx) contains a header row, a logo, and named cells where data is dropped. The VBScript opens the file, fills in the cells, saves a timestamped copy, and closes Excel without leaving an orphan process.
4.1 Pre-built template layout
| Cell | Content |
|---|---|
| B2 | Operator name (read from a WinCC internal tag) |
| B3 | Shift start (system time formatted as yyyy-mm-dd hh:nn) |
| B4 | Plant state (read from ProcessState tag) |
| D2:D20 | Counter values for the shift (20 internal counters) |
| F2:F20 | Matching units (text from configuration tags) |
4.2 VBScript code — production template
' WinCC VBScript: Export shift report to Excel
' Tested on WinCC V7.5 SP2, WinCC V8.0, WinCC Professional V17
' Author: WinCC engineering, 2024
Option Explicit
Const TEMPLATE_PATH = "C:\WinCCReports\Template\ShiftReport.xlsx"
Const OUTPUT_FOLDER = "C:\WinCCReports\Out\"
Const MAX_CELL_COLUMN = 6 ' column F
Const MAX_CELL_ROW = 20 ' row 20
Dim objExcelApp, objWorkbook, objWorkSheet, objFSO, objFolder
Dim objTag, strOperator, dtmShiftStart, strPlantState
Dim strDateStamp, strOutPath, iRow, iCol
Dim intRC
' --- 1. Build timestamped output path -----------------------------------
strDateStamp = Year(Now) & "-" & Right("0" & Month(Now), 2) & "-" & _
Right("0" & Day(Now), 2) & "_" & _
Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2)
strOutPath = OUTPUT_FOLDER & "Shift_" & strDateStamp & ".xlsx"
' --- 2. Ensure output folder exists ------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(OUTPUT_FOLDER) Then
objFSO.CreateFolder OUTPUT_FOLDER
End If
' --- 3. Launch Excel COM -----------------------------------------------
On Error Resume Next
Set objExcelApp = CreateObject("Excel.Application")
If Err.Number <> 0 Then
HMIRuntime.Trace "Excel launch failed: " & Err.Number & " " & Err.Description & vbCrLf
Err.Clear
Exit Sub
End If
On Error Goto 0
objExcelApp.Visible = False
objExcelApp.DisplayAlerts = False
objExcelApp.ScreenUpdating = False
objExcelApp.EnableEvents = False
' --- 4. Open template --------------------------------------------------
If Not objFSO.FileExists(TEMPLATE_PATH) Then
HMIRuntime.Trace "Template not found: " & TEMPLATE_PATH & vbCrLf
objExcelApp.Quit
Set objExcelApp = Nothing
Exit Sub
End If
Set objWorkbook = objExcelApp.Workbooks.Open(TEMPLATE_PATH, , True) ' ReadOnly = True
Set objWorkSheet = objWorkbook.Worksheets(1)
' --- 5. Read tags and populate cells ----------------------------------
Set objTag = HMIRuntime.Tags("Operator")
objTag.Read
strOperator = CStr(objTag.Value)
objWorkSheet.Cells(2, 2).Value = strOperator
dtmShiftStart = Now
objWorkSheet.Cells(3, 2).Value = FormatDateTime(dtmShiftStart, vbShortDate) & " " & _
FormatDateTime(dtmShiftStart, vbShortTime)
Set objTag = HMIRuntime.Tags("ProcessState")
objTag.Read
strPlantState = CStr(objTag.Value)
objWorkSheet.Cells(4, 2).Value = strPlantState
' --- 6. Loop through counter tags -------------------------------------
For iRow = 2 To MAX_CELL_ROW
Set objTag = HMIRuntime.Tags("Counter_" & Right("0" & iRow, 2))
objTag.Read
If Err.Number = 0 Then
objWorkSheet.Cells(iRow, 4).Value = CDbl(objTag.Value)
Else
objWorkSheet.Cells(iRow, 4).Value = "ERR"
Err.Clear
End If
Set objTag = HMIRuntime.Tags("Unit_" & Right("0" & iRow, 2))
objTag.Read
objWorkSheet.Cells(iRow, 6).Value = CStr(objTag.Value)
Next
' --- 7. Save as timestamped workbook ----------------------------------
objWorkbook.SaveAs strOutPath, 51 ' xlOpenXMLWorkbook = 51 (.xlsx)
' --- 8. Clean up -------------------------------------------------------
objWorkbook.Close False
objExcelApp.Quit
Set objWorkSheet = Nothing
Set objWorkbook = Nothing
Set objExcelApp = Nothing
Set objFSO = Nothing
HMIRuntime.Trace "Shift report saved: " & strOutPath & vbCrLf
4.3 What the constants mean
| Constant | WinCC/Excel meaning |
|---|---|
| 51 | Excel xlFileFormat value for .xlsx (Office Open XML). Use 56 for .xls (Excel 97-2003). |
| 3 |
xlQualityCenter; not used here. Excel format codes run 1-49 native, 50+ require the matching file extension. |
vbShortDate / vbShortTime
|
System-locale dependent. Replace with explicit Format(now,"yyyy-mm-dd") for international rollouts. |
5. Method 2 — Creating a New Workbook Per Day with a Timestamped Filename
When no template exists, the script creates a fresh workbook, writes a header row, and saves it. The convention YYYY-MM-DD_HHMM.xlsx sorts naturally in any file browser and prevents collisions when the script is run twice within the same minute.
' WinCC VBScript: Create a new dated workbook
' Run from a button OnClick or a global action triggered by a tag change
Option Explicit
Dim objExcel, objWorkbook, objWorkSheet, objFSO
Dim strDate, strPath, strFileName
' --- Build path ---
strDate = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2)
strFileName = "Report_" & strDate & ".xlsx"
strPath = "C:\WinCCReports\" & strFileName
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists("C:\WinCCReports") Then
objFSO.CreateFolder "C:\WinCCReports"
End If
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.DisplayAlerts = False
' --- Open or create ---
If objFSO.FileExists(strPath) Then
Set objWorkbook = objExcel.Workbooks.Open(strPath)
Set objWorkSheet = objWorkbook.Worksheets(1)
Else
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorkSheet = objWorkbook.Worksheets(1)
objWorkSheet.Cells(1,1).Value = "Timestamp"
objWorkSheet.Cells(1,2).Value = "TagName"
objWorkSheet.Cells(1,3).Value = "Value"
objWorkSheet.Cells(1,4).Value = "Quality"
End If
' --- Append row ---
Dim intLastRow
intLastRow = objWorkSheet.Cells(objWorkSheet.Rows.Count, 1).End(-4162).Row + 1 ' xlUp = -4162
objWorkSheet.Cells(intLastRow, 1).Value = Now
Set objTag = HMIRuntime.Tags("Tank1_Level")
objTag.Read
objWorkSheet.Cells(intLastRow, 2).Value = "Tank1_Level"
objWorkSheet.Cells(intLastRow, 3).Value = objTag.Value
objWorkSheet.Cells(intLastRow, 4).Value = objTag.Quality
' --- Save and quit ---
objWorkbook.Save
objWorkbook.Close False
objExcel.Quit
Set objWorkSheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
Set objFSO = Nothing
objWorkSheet.Cells(...).End(-4162).Row with UsedRange.Rows.Count + 1 if you support mixed-region appends. The End(xlUp) walk stops on the first empty cell; long gaps caused by formatted-but-empty rows will be missed.6. Method 3 — Daily File with Date-Only Filename
For shift-overwrite behaviour, where the operator appends all day to one file and the file is closed/archived at midnight, the filename contains only the date. The script checks for existence, opens if present, creates if not.
Dim dtmDate, objExcel, objWorkbook, strPath
dtmDate = Date ' returns the current system date
strPath = "C:\Reports\Shift_" & Year(dtmDate) & "-" & _
Right("0" & Month(dtmDate), 2) & "-" & _
Right("0" & Day(dtmDate), 2) & ".xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
If CreateObject("Scripting.FileSystemObject").FileExists(strPath) Then
Set objWorkbook = objExcel.Workbooks.Open(strPath)
' TODO: append rows
Else
Set objWorkbook = objExcel.Workbooks.Add()
objWorkbook.SaveAs strPath, 56 ' xlExcel8 = 56 (.xls legacy)
' TODO: write header
End If
objWorkbook.Save
objWorkbook.Close False
objExcel.Quit
Set objWorkbook = Nothing
Set objExcel = Nothing
7. Common Runtime Issues and Root Causes
| Symptom | Hex / WinCC error | Root cause | Fix |
|---|---|---|---|
| "ActiveX component can't create object" | 0x80040154 | Excel not installed; bitness mismatch (32-bit WinCC vs 64-bit Excel); DCOM launch denied | Install matching Excel bitness; grant DCOM launch permission to the WinCC runtime user |
| Script hangs, no error | n/a | Excel displays a modal dialog (file open, save prompt, compatibility warning) | Set objExcel.DisplayAlerts = False and .ScreenUpdating = False before any operation |
| Excel process remains in Task Manager after script | n/a | Missing objExcel.Quit or Set objExcel = Nothing; early Exit Sub after COM instantiation |
Always use the cleanup pattern; add the cleanup block to error handlers |
| Tag value writes "Empty" or 0 | n/a | Tag was not .Read before .Value access |
Always call objTag.Read first; check objTag.LastError
|
| Script runs but file is not updated | n/a | Working directory redirection; UAC virtual store; network share not reachable | Use absolute path; run RT elevated; verify share with net use
|
| "Subscript out of range" | 0x800A0009 | Tag name typo; tag not defined in WinCC project | Validate tag name in WinCC Explorer; use HMIRuntime.Tags(...).LastError
|
| Excel file locked, second run fails | 0x800A03EC | Previous Excel instance still owns the file; non-Unicode characters in name | Always .Quit; sanitise filenames; or use Kill + recreate in a retry loop |
| All values write to a single cell | n/a | Used objWorkSheet.Range("A1") without .Cells(row,col) form |
Use Cells(row, col) for programmatic addressing |
For background on the WinCC tag object and its LastError property, see the SIMATIC WinCC V7.5 SP2 Manual Collection, chapter "VBS reference".
8. Performance and Stability Limits
Excel automation is convenient but not high-throughput. Field data from Siemens support escalations indicates the following practical limits on a WinCC RT station (Intel Core i5 / 8 GB RAM / 64-bit Windows 10 LTSC, Excel 2019 32-bit):
| Operation | Sustainable rate | Bottleneck |
|---|---|---|
| Append one row to an open workbook | 5–10 rows/s | CELL write through COM dispatch |
| Write 1,000 rows then save | 1,000 rows / 30 s | Range object bulk write vs. cell-by-cell |
| Concurrent script invocations | 1 (serialize) | Excel is single-instance COM; second instance collides |
| Concurrent script invocations (with retry) | 3–5 with 250 ms semaphore | Use a named mutex or file-lock |
| Maximum sustainable workbook size | ~50,000 rows / 25 MB | Excel memory + WinCC VBS heap |
To exceed 10 rows/s, switch to objWorkSheet.Range(startCell, endCell).Value = array where array is a 2-D VBScript array built from tag reads. This bypasses per-cell COM dispatch and is typically 30× faster.
' Bulk write 1000 tag values into a 2-D array in one COM call
Dim arrData(999, 1) ' 1000 rows, 2 columns
Dim i
For i = 0 To 999
Set objTag = HMIRuntime.Tags("Tag_" & (i + 1))
objTag.Read
arrData(i, 0) = objTag.Timestamp
arrData(i, 1) = objTag.Value
Next
objWorkSheet.Range("A2:B1001").Value = arrData
CreateObject("Excel.Application") will each get a new Excel process (Excel supports multiple COM instances). However, when both scripts open the same file, the second Workbooks.Open returns a read-only view and any Save fails with 0x800A03EC. Serialize with a global VBS variable or a named mutex.9. DataMonitor / PMOPEN EXPORT Alternative
When scheduled, formula-driven Excel reports from TagLogging or AlarmLogging archives are required, install the SIMATIC WinCC/DataMonitor option. The PMOPEN EXPORT add-on publishes a configured report template against an archive, regenerates the workbook at a configurable time, and deposits the result in a user-defined path or sends it by e-mail. The setup is documented in the WinCC DataMonitor manual at SIMATIC WinCC V8.1 Documentation.
| Capability | VBScript + Excel COM | DataMonitor / PMOPEN |
|---|---|---|
| Real-time live values | Yes | No (archive snapshot only) |
| Historical archive data | Via OLE DB, complex | Built-in, time range picker |
| Excel formula evaluation in template | Manual, in code | Yes — formulas re-execute per regeneration |
| Web client access | No | Yes (WebCenter portal) |
| Schedulable | External Windows Task Scheduler | Built-in scheduler |
| Required additional license | None (Excel license only) | WinCC DataMonitor license |
10. Connectivity Pack — The OPC / OLE DB Route
If the requirement is Excel reading WinCC rather than WinCC writing Excel, the direction is reversed. Install the WinCC Connectivity Pack, which exposes the OPC UA server, the WinCC OLE DB provider (CC_OpenArch and CC_Read stored procedures), and the WinCC REST connector. Excel 2016+ can then pull data via Power Query → From OLE DB or From Web, refreshing on open or on a timer. The Connectivity Pack manual is shipped with the WinCC V8 install media and indexed at SIMATIC WinCC V8.0 Knowledge Base.
For Power Query import patterns on the Microsoft side, see Export data to Excel — Microsoft Support. For the inverse direction, where a Power BI report pushes data back to Excel, see Export data from a Power BI visualization — Microsoft Learn.
11. Step-by-Step Deployment Procedure (WinCC V7.5 SP2)
- Open WinCC Explorer, navigate to Global Script → C-Editor / VBS-Editor.
- Right-click VBS-Editor, choose New → Action, name it
ExportShiftReport. - Paste the production template from Section 4.2 into the editor.
- Open the trigger configuration (right-click the action → Information tab). Add a trigger:
- Type: Tag, tag =
ShiftEnd(a Boolean internal tag you set from the HMI) - Cycle: 250 ms (WinCC will fire on rising edge only when Event is selected)
- Type: Tag, tag =
- Optionally add a button in the desired picture; bind its Mouse Click event to a new action that calls
ExportShiftReportdirectly. - Compile (F7). Check the Output window for syntax errors.
- Create the template
C:\WinCCReports\Template\ShiftReport.xlsxwith the layout from Section 4.1. - Verify folder
C:\WinCCReports\Out\exists or let the script create it. - Start WinCC Runtime, trigger the action, and confirm the file appears.
12. Step-by-Step Deployment Procedure (TIA Portal, WinCC Professional V17)
- In the TIA Portal project tree, open WinCC RT Professional → Screens and select the screen with the report button.
- Add a button. In Properties → Events → Click, choose Add VBScript.
- Paste the script (note: in TIA Portal WinCC Professional the object model is the same —
HMIRuntime.Tags,CreateObject— but the project name is implicit and the tag list is filtered by screen scope). - Compile the script (Project tree → Scripts → Compile).
- Download the project to the RT station.
- On the RT station, run WinCC Runtime and trigger the action.
CreateObject for Excel. The Excel automation method is restricted to WinCC Professional (TIA) and WinCC V7.x on a PC runtime. For Comfort/Advanced panels, use the integrated Report functionality in the panel or copy the data to a USB stick and process off-line.13. Verification Checklist
| Check | How to verify | Pass criterion |
|---|---|---|
| Excel launches | Task Manager shows EXCEL.EXE during script run | Process appears and disappears |
| File created | Watch the output folder with File Explorer | File with timestamped name appears |
| Tag values written | Open the file, check cells | Values match HMI faceplate |
| No orphan Excel | Task Manager after script completes | Zero EXCEL.EXE processes |
| WinCC trace | WinCC Explorer → Tools → Trace | "Shift report saved: ..." line present |
| Bit width | About Excel → Help; about WinCC → Project properties | Both 32-bit or both 64-bit |
| DCOM permissions | Run as WinCC user; excel /automation
|
Excel starts headless without prompt |
| File lock clean | Run script twice in succession | Second run succeeds; no 0x800A03EC |
| Date format locale-safe | Change Windows region to de-DE and re-run | Filename still parses as expected |
| Network share reachable |
dir \server\share as WinCC user |
Path visible; write permission present |
14. Security and Hardening Recommendations
- Run the WinCC RT service under a dedicated domain account, not LocalSystem, so DCOM permissions can be set on a user principal.
- Configure the Excel COM DCOM entry to disallow Remote launch. Only Local launch is needed.
- Disable Excel macros in the template workbook. The template should not contain VBA; the WinCC VBScript is the only code path.
- Use a dedicated report share with NTFS ACLs that allow only the WinCC RT group to write and an audit group to read.
- Log every report generation to the WinCC audit trail by appending a row to a SQL archive via
CreateObject("ADODB.Connection")in the same script. - Restrict the script to read-only tags where possible; use the
objTag.Writepath only when the operator explicitly confirms a value.
15. Frequently Asked Questions
Why does CreateObject("Excel.Application") fail with error 0x80040154 on a WinCC runtime station?
The most common cause is a bit-width mismatch between WinCC and Excel, or DCOM launch permission not granted to the WinCC runtime user. Install Excel at the same bitness (32-bit or 64-bit) as the WinCC process, then in dcomcnfg.exe set launch and access permissions on the Microsoft Excel Application DCOM entry for the WinCC user account. Verify with excel /automation from a command prompt run as that user.
Can the script run on a Comfort or Basic panel?
No. WinCC Comfort Panels, Basic Panels, and RT Advanced do not host the COM runtime required to drive Excel. For those targets, use the panel's built-in Report function (System → Report) or transfer the logged data to a USB stick and process it on a PC. Excel automation is only available on WinCC Professional (TIA) and WinCC V7.x running on a Windows PC.
How do I create a new Excel file every day with the date as the filename?
Build the filename from Date() or Now() with a yyyy-mm-dd pattern (Section 5 and Section 6). Use the Scripting.FileSystemObject to test FileExists; create with Workbooks.Add and SaveAs path, 51 for .xlsx or 56 for .xls. If the file already exists, Workbooks.Open it and append instead of overwriting.
How can I read WinCC live data from inside Excel instead of writing it from WinCC?
Reverse the data flow. Install the WinCC Connectivity Pack, then connect Excel via Power Query to either the OPC UA server or the WinCC OLE DB provider. The CC_OpenArch and CC_Read stored procedures expose TagLogging and AlarmLogging archives as SQL queryable tables. This path does not require a VBScript action and refreshes on demand from inside Excel.
Why does an EXCEL.EXE process remain in Task Manager after the script completes?
Either the script exited early (after the COM instantiation but before objExcel.Quit) or an object reference was not released. Move the cleanup block — objWorkbook.Close, objExcel.Quit, and Set ... = Nothing for every Excel object — into an error handler and an On Error Resume Next tail. Closing the WinCC Runtime will normally release any leaked COM instances, but in long-running RT processes the leak accumulates until the OLE heap is exhausted.
What is the fastest way to export thousands of rows to Excel from a VBScript action?
Build a 2-D VBScript array from the tag reads, then assign it in a single COM call: objWorkSheet.Range("A2:B1001").Value = arrData. This bypasses per-cell COM dispatch and is typically 20-30 times faster than calling objWorkSheet.Cells(...).Value = ... for each cell. Above 50,000 rows or 25 MB, switch to writing a CSV file directly with FileSystemObject.CreateTextFile and import it into Excel via Power Query.
Does the DataMonitor option replace the need for custom VBScript reporting?
For scheduled, template-driven reports from TagLogging or AlarmLogging archives, DataMonitor (PMOPEN EXPORT) is the correct tool. For ad-hoc operator-triggered reports, snapshot exports of live values, or reports that need values from PLC tags that are not configured in the archive, custom VBScript remains the practical choice. The two mechanisms coexist in the same WinCC project without conflict.