Overview of WinCC-to-Excel Data Export Paths
Siemens WinCC provides three documented paths for moving runtime tag values into Microsoft Excel or a structured CSV file without purchasing third-party add-ons:
- WinCC Trend Control export — runtime-driven, manual or triggered export from an HMI Trend view.
- VBScript with FileSystemObject — programmable, event-driven, works in WinCC V7.x Runtime and TIA Portal WinCC RT Advanced/Professional.
- TIA Portal Data Logging — function-block based CSV logging (TiaPortal V11+), ideal for cyclic 1 s+ logging and persistent archives.
All three paths produce a delimited text file (CSV) that Excel opens natively. None of them require Microsoft Office automation on the runtime PC; the file is generated server-side and Excel only renders it. The choice between methods depends on the trigger model (event vs. cyclic), number of tags, the HMI platform, and whether the source project uses WinCC V7 (classic) or TIA Portal WinCC.
Prerequisites
| Prerequisite | WinCC V7.x | TIA Portal WinCC |
|---|---|---|
| Configured HMI tags (internal or external via PLC) | Required | Required |
| Runtime license (RC/RT) | WinCC RT 7.0 SP3 minimum for trend export | WinCC RT Advanced / Professional |
| User rights to write to target path | Local user / WinCC service account needs write permission | Same; avoid %ProgramFiles% paths |
| VBScript runtime | Bundled with WinCC | Bundled with TIA Portal WinCC |
| TIA Portal version for Data Logging | Not applicable | TIA Portal V11 SP2 or later; V13+ recommended |
Reference the official Siemens manual set:
- SIMATIC HMI WinCC V7.5 — Programming and Reference Manual
- SIMATIC WinCC Engineering V18 — Manual
- WinCC V7.0 SP3 — VBScript Reference
- TIA Portal Openness / WinCC Scripting Manual
Method 1 — WinCC Trend Control Export
WinCC Trend Control ships with an export toolbar button that writes the currently displayed time window into a CSV or Excel-compatible file. This is the lowest-effort path and is suitable when the user is already viewing a trend and needs a snapshot.
Step-by-step configuration
- Open Graphics Designer and insert an "Online Trend Control" (WinCC V7.x) or "WinCC Online Trend Control" (TIA Portal).
- Configure the trend under Properties > Trends and add the WinCC tags you want to log.
- Under Properties > Toolbar, enable the "Export data" button (icon: floppy disk with arrow). Verify the button shows up in Runtime.
- Define the export format:
CSV (separator: semicolon)is the default Excel-friendly format for European locales. - Trigger Runtime, populate the trend, click the export button, choose a writable path such as
D:\Logs\orC:\Users\Public\Documents\WinCCLogs\.
The output file contains a time stamp column, a status column, and one column per configured trend. Excel reads the file via Data > From Text/CSV with semicolon as the delimiter.
Method 2 — VBScript with FileSystemObject (Most Flexible)
VBScript runs on events such as tag value change, button click, or scheduler. The script reads tag values through HMIRuntime.Tags(...).Read and writes them as a CSV row via CreateObject("Scripting.FileSystemObject"). This works in WinCC V7.x and TIA Portal WinCC Runtime.
Minimal single-tag script
' Trigger: tag change event or button-click event in a WinCC screen
Dim f, ts, DataSet
Dim tagName, tagValue
tagName = "Tag1"
tagValue = HMIRuntime.Tags(tagName).Read
DataSet = CStr(Now) & ";" & tagValue & vbCrLf
Set f = CreateObject("Scripting.FileSystemObject")
Set ts = f.OpenTextFile("D:\Logs\Export.csv", 8, True) ' 8 = ForAppending, True = create if missing
ts.Write DataSet
ts.Close
Set ts = Nothing
Set f = Nothing
Multi-tag single-row script
The most common field issue is that a script with sequential DataSet = ... assignments appears to overwrite the previous line. The fix is to concatenate the values into one string with a delimiter, then write once.
' Multi-tag capture: timestamp + N tags in one CSV row
Dim f, ts, DataSet
Dim sep, nowStr
sep = ";"
nowStr = CStr(Now)
' Build the CSV row by concatenation (NOT overwriting)
DataSet = nowStr & sep
DataSet = DataSet & CStr(HMIRuntime.Tags("xxx1").Read) & sep
DataSet = DataSet & CStr(HMIRuntime.Tags("xxx2").Read) & sep
DataSet = DataSet & CStr(HMIRuntime.Tags("xxx3").Read) & sep
DataSet = DataSet & CStr(HMIRuntime.Tags("xxx4").Read) & vbCrLf
Set f = CreateObject("Scripting.FileSystemObject")
Set ts = f.OpenTextFile("D:\Logs\Export.csv", 8, True)
ts.Write DataSet
ts.Close
Set ts = Nothing
Set f = Nothing
DataSet = CStr(Now) & ";" & HMIRuntime.Tags("xxx1").Read in sequence will, by VBScript semantics, overwrite the previous assignment. Each line must be appended using & on the previous variable, not start with DataSet = as a fresh assignment per tag.Scaling to many tags
For ten or more tags, build a dynamic array rather than hard-coding concatenation. This keeps the script maintainable and avoids line-length limits.
' Array-driven multi-tag capture (TIA Portal WinCC / WinCC V7.x compatible)
Dim f, ts, header, line, i
Dim tagList
tagList = Array("MotorCurrent", "TankLevel", "Pressure", "Temperature", "FlowRate")
' Build header on first run only
Set f = CreateObject("Scripting.FileSystemObject")
If Not f.FileExists("D:\Logs\Export.csv") Then
Set ts = f.CreateTextFile("D:\Logs\Export.csv", True, False)
header = "Timestamp"
For i = LBound(tagList) To UBound(tagList)
header = header & ";" & tagList(i)
Next
ts.WriteLine header
ts.Close
End If
' Append a new data row
Set ts = f.OpenTextFile("D:\Logs\Export.csv", 8, True)
line = CStr(Now)
For i = LBound(tagList) To UBound(tagList)
line = line & ";" & CStr(HMIRuntime.Tags(tagList(i)).Read)
Next
ts.WriteLine line
ts.Close
Semicolon vs. comma delimiters
Excel's locale-dependent default CSV separator makes German/French locales open comma-delimited files incorrectly. Force semicolon separation, which is the Excel default in those regions and avoids the "all data in one column" symptom.
| Locale | Decimal separator | Excel default CSV delimiter | Recommended VBScript delimiter |
|---|---|---|---|
| en-US | . | comma | comma (or semicolon) |
| de-DE / fr-FR | , | semicolon | semicolon |
| Mixed / exported from HMI | n/a | n/a | Use semicolon for safest cross-locale behavior |
Method 3 — TIA Portal Data Logging (Cyclic Archive)
For cyclic logging at intervals as fast as 1 s, the recommended Siemens path is the Data Logging mechanism introduced in TIA Portal V11 SP2. This avoids the per-event script overhead and writes a managed CSV/SQLite archive directly from the HMI runtime.
Implementation outline
- In the TIA Portal project tree, open HMI Tags and confirm the tags to log are present and accessible from the HMI.
- Open Logs under HMI device, add a new Data log.
- Add columns matching the tags you want logged; configure the data type per column (BOOL, INT, REAL, STRING).
- Set logging mode to Cyclic or Event-triggered. For 1-second intervals select cyclic with a 1 s period; for a trigger bit select the trigger tag.
- Configure the storage path. The default is on the HMI's local storage or a configured network share. Recommended:
\Storage Card\Logs\for Unified Comfort Panels,D:\Logs\for PC Runtime. - Insert the function block
LG_Datalog(TIA Portal V13+) in your PLC program or use the equivalent HMI-sideDataLogTriggersystem function to start/stop logging from the PLC.
The resulting CSV opens directly in Excel and contains a header row plus one row per logging cycle. Multiple header rows are not produced by Data Logging itself, which avoids the "second header" complaint common with manual VBScript logging.
TriggerLog. Edge-detect it in the HMI script or in the PLC. If using the DataLogTrigger HMI system function, a rising edge starts a new logging session and writes a separator row, while a falling edge closes the file cleanly.Trigger Models Compared
| Trigger source | Suitable method | Minimum granularity | Notes |
|---|---|---|---|
| Manual user button click | VBScript on button event | Per click | Best for operator-initiated snapshots |
| Tag value change | VBScript on tag-change event | Per change | Avoid on fast-changing tags; throttling required |
| Scheduler (e.g. every 5 s) | WinCC Scheduler triggering VBScript | 1 s | Built-in cyclic scheduler; no PLC code needed |
| PLC trigger bit | VBScript on tag event or Data Logging trigger | 1 s | Standard pattern for production data archiving |
| Cyclic 1 s log | TIA Portal Data Logging | 1 s | More efficient than per-second VBScript |
Handling Multiple Headers in the CSV
A frequent follow-up question is: "how do I add a second header row to segregate data, for example by shift or by batch?" Two clean approaches:
-
Per-file headers: close the current CSV file at the shift boundary and open a new file named
Export_ShiftA_20250115.csv. Each file receives its own header automatically because the script checks for file existence. -
Inline separator rows: write a literal header row string before appending the data block, e.g.
ts.WriteLine "=== Shift B start ===", then continue appending rows.
' Inline separator row example
Set ts = f.OpenTextFile("D:\Logs\Export.csv", 8, True)
ts.WriteLine "" ' blank row
ts.WriteLine "=== Batch #" & HMIRuntime.Tags("BatchNumber").Read & " start at " & CStr(Now) & " ==="
ts.WriteLine header
' continue appending data rows below
ts.Close
Excel treats any line that does not match the column count as text. After import, use Data > Filter to hide the separator rows.
File Path, Encoding, and Locale
Three field-proven rules to avoid corrupted exports:
-
Always use an ASCII-safe absolute path. Avoid mapped network drives without persistent reconnection; UNC paths like
\\SERVER\Share\Logs\work but require the WinCC service account to have write permission. Siemens HMI Scripting reference, section "File System Access" documents the supported path conventions. -
Use Unicode (UTF-8) or system ANSI.
CreateTextFile(path, overwrite, unicode)withunicode=Falsewrites ANSI (matches Excel on the same machine). Passunicode=Trueif the file will be opened on systems with different code pages. -
Encode numeric tags as strings before concatenation.
CStr(HMIRuntime.Tags("Pressure").Read)prevents type-mismatch runtime errors when the PLC briefly writes an invalid value.
Error Codes and Failure Modes
| Symptom | Likely cause | WinCC error / HRESULT | Remedy |
|---|---|---|---|
| Script runtime error "Permission denied" | Write path under C:\Program Files\ or read-only share |
0x800A0046 | Move logs to D:\Logs\ or a writable UNC share; grant the WinCC runtime user write permission |
| CSV opens in Excel with all data in one column | Locale expects semicolon but file used comma | None (Excel warning) | Switch delimiter to ; or use Excel's Data > Text to Columns
|
| Only first tag written; remaining tags missing |
DataSet = ... re-assigned instead of appended |
None (logic error) | Use DataSet = DataSet & ... for each subsequent tag |
| Tag read returns empty / invalid | Tag not in HMI tag DB or wrong name | HMIRuntime returns empty string or 0 | Verify tag name in project tree; check PLC connection status |
| File grows without bound | No rotation configured | None | Add scheduler that renames Export.csv to Export_YYYYMMDD_HHMMSS.csv when size exceeds threshold |
Unicode characters appear as ???
|
File written in ANSI but read as UTF-8 | None (display only) | Write file with unicode=True or use only ASCII tag names |
| Script runs but file does not appear | Trigger event not firing | None | Verify the trigger event in the screen's Events tab is wired to the script |
| Data Logging CSV shows stale values | PLC connection lost | WinCC connection status = "Disconnected" | Restore PLC/HMI connection; values will resume on reconnect |
Verification Procedure
- Start WinCC Runtime and force the trigger event (click the configured button, set the trigger tag in the PLC, or wait for the scheduler).
- Confirm the target CSV exists at the configured path. Open it in Notepad to verify line count, separator, and that each row contains all expected tag values.
- Open the CSV in Excel using Data > From Text/CSV. Confirm that columns align with the configured tags, that the timestamp column parses as a date, and that numeric columns format correctly.
- For Data Logging, check the HMI's Diagnostics > Logs view to confirm the log status is
Runningand the cycle count is incrementing. - Run a stress test: trigger the script 1,000 times in a loop using the scheduler and confirm that no rows are dropped and no file lock errors occur.
Troubleshooting Decision Tree
- Is the file being created at all? If not → check path permissions and trigger event wiring.
- Is the file created but empty? → the tag read is failing; check tag spelling and PLC connection.
- Are values wrong (not what the PLC shows)? → confirm tag is mapped to the correct PLC address; verify update cycle.
- Are values correct but only one tag per row? → fix the VBScript concatenation pattern as shown above.
- Does Excel not split columns? → switch delimiter to semicolon or use Text-to-Columns wizard.
- Does the file grow huge? → add rotation by renaming on size threshold or by scheduler.
Best Practices and Field Tips
-
Use a dedicated folder. Create
D:\Logs\(or platform-specific equivalent) before the first run. Do not write toC:\Program Files\or to a network share that may be temporarily offline. - Include a header row only once. Use a file-exists check to write the header on the first record only.
-
Format timestamps deterministically.
Format(Now, "yyyy-mm-dd hh:nn:ss")sorts correctly in Excel;Nowuses locale-dependent formatting. -
Convert numbers with CStr. Always wrap tag reads in
CStr(...)to handle type changes gracefully. -
Free COM objects. Set
fandtstoNothingafter use to release file handles. Repeated opens without release cause WinCC to exhaust file handles within hours. - For high-frequency logging, prefer Data Logging. VBScript with a 1 s scheduler works but is less efficient than the native data log mechanism.
- For Trend Control export, configure decimal places on the trend axis to control CSV precision.
- Document the trigger in the screen's comment so future maintainers know whether the script is button-driven, tag-driven, or scheduler-driven.
Reference: Function and Property Summary
| Object / Method | Purpose | Notes |
|---|---|---|
HMIRuntime.Tags(name).Read |
Read HMI tag value | Returns variant; convert with CStr/CInt/CDbl |
HMIRuntime.Tags(name).Write value |
Write to HMI tag | Requires the tag to be writable |
CreateObject("Scripting.FileSystemObject") |
File and folder operations | Always Set to Nothing after use |
FSO.OpenTextFile(path, 8, True) |
Open file in append mode, create if missing | 8 = ForAppending; True = create |
FSO.CreateTextFile(path, True, False) |
Create new file, overwrite if exists | Third arg: False = ANSI, True = Unicode |
FSO.FileExists(path) |
Check existence before writing header | Prevents duplicate headers |
LG_Datalog (TIA Portal FB) |
Manage data logs from PLC | Available TIA Portal V13+ |
DataLogTrigger (HMI system function) |
Start/stop data logging from HMI | Rising edge = start, falling edge = stop |
How do I export WinCC tags to Excel without buying extra software?
Use the built-in WinCC Trend Control export button for snapshots, or write a VBScript that reads HMI tags with HMIRuntime.Tags(...).Read and writes them to a CSV file using FileSystemObject. CSV files open in Excel directly without any additional license. For cyclic 1 s logging, TIA Portal's native Data Logging (TIA V11 SP2+) produces CSV/SQLite archives without third-party tools.
Why does my VBScript only write the first tag and ignore the rest?
The classic bug is re-assigning the DataSet variable instead of appending to it. Use DataSet = DataSet & CStr(HMIRuntime.Tags("xxx2").Read) & ";" for every tag after the first, never a fresh DataSet = ... assignment per tag. The single-variable name then contains all values concatenated with the delimiter.
How can I add a second header to my CSV to separate batches or shifts?
Two clean options: (1) close the current CSV at the boundary and open a new file named with the shift or batch ID, so each file gets its own header automatically, or (2) write a literal separator text row such as "=== Shift B start ===" before the data block and a fresh header line, then continue appending. Excel treats unmatched lines as text; use Data > Filter to hide them after import.
What WinCC version is required for VBScript-based export?
VBScript with FileSystemObject is supported in WinCC V7.0 SP3 and later, and in all TIA Portal WinCC Runtime versions (Advanced and Professional). The HMIRuntime object, Tag.Read/Tag.Write methods, and the VBScript runtime are bundled with WinCC; no add-on license is required for these features. Data Logging as a managed mechanism is TIA Portal V11 SP2 or later, with the LG_Datalog FB available from V13+.
My CSV opens in Excel with all data in a single column. What went wrong?
This is the classic locale mismatch. German, French, and most European Excel versions default to semicolon as the CSV separator while English Excel defaults to comma. Either change the script delimiter to semicolon (";") for cross-locale compatibility or use Excel's Data > Text to Columns wizard with the correct delimiter. Always write CStr-converted numeric values and use semicolons in mixed-locale deployments to avoid the symptom entirely.
How do I trigger the export from a specific PLC bit?
Wire the trigger BOOL tag to the script's event in the screen (Events tab > "On change" or "Rising edge"). In TIA Portal WinCC, you can alternatively use the HMI system function DataLogTrigger, where a rising edge of the trigger tag starts a logging session and a falling edge closes it cleanly. The PLC code simply sets the trigger BOOL when a snapshot is needed; the HMI runtime handles the file I/O.