Exporting WinCC Tags to Excel: VBScript and Data Logging Methods

David Krause14 min read
SiemensTutorial / How-toWinCC
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

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:

  1. WinCC Trend Control export — runtime-driven, manual or triggered export from an HMI Trend view.
  2. VBScript with FileSystemObject — programmable, event-driven, works in WinCC V7.x Runtime and TIA Portal WinCC RT Advanced/Professional.
  3. 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.

Platform identification first. Determine the project origin (WinCC V7.x vs. TIA Portal WinCC) before picking a method. WinCC V7.x supports both the Trend export button and VBScript. TIA Portal WinCC V11+ adds native Data Logging blocks. VBScript syntax differs slightly between the two platforms for tag read/write objects.

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:

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

  1. Open Graphics Designer and insert an "Online Trend Control" (WinCC V7.x) or "WinCC Online Trend Control" (TIA Portal).
  2. Configure the trend under Properties > Trends and add the WinCC tags you want to log.
  3. Under Properties > Toolbar, enable the "Export data" button (icon: floppy disk with arrow). Verify the button shows up in Runtime.
  4. Define the export format: CSV (separator: semicolon) is the default Excel-friendly format for European locales.
  5. Trigger Runtime, populate the trend, click the export button, choose a writable path such as D:\Logs\ or C:\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.

Limitation: the trend export only contains tags that are bound to a trend in the visualization. If a tag is not displayed, it cannot be exported through the trend button. For tags that you do not want to plot, use VBScript or Data Logging instead.

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
Common bug: writing four separate lines such as 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

  1. In the TIA Portal project tree, open HMI Tags and confirm the tags to log are present and accessible from the HMI.
  2. Open Logs under HMI device, add a new Data log.
  3. Add columns matching the tags you want logged; configure the data type per column (BOOL, INT, REAL, STRING).
  4. 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.
  5. 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.
  6. Insert the function block LG_Datalog (TIA Portal V13+) in your PLC program or use the equivalent HMI-side DataLogTrigger system 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.

Trigger-bit pattern: use a dedicated BOOL tag such as 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:

  1. 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.
  2. 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:

  1. 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.
  2. Use Unicode (UTF-8) or system ANSI. CreateTextFile(path, overwrite, unicode) with unicode=False writes ANSI (matches Excel on the same machine). Pass unicode=True if the file will be opened on systems with different code pages.
  3. 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

  1. Start WinCC Runtime and force the trigger event (click the configured button, set the trigger tag in the PLC, or wait for the scheduler).
  2. 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.
  3. 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.
  4. For Data Logging, check the HMI's Diagnostics > Logs view to confirm the log status is Running and the cycle count is incrementing.
  5. 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

  1. Is the file being created at all? If not → check path permissions and trigger event wiring.
  2. Is the file created but empty? → the tag read is failing; check tag spelling and PLC connection.
  3. Are values wrong (not what the PLC shows)? → confirm tag is mapped to the correct PLC address; verify update cycle.
  4. Are values correct but only one tag per row? → fix the VBScript concatenation pattern as shown above.
  5. Does Excel not split columns? → switch delimiter to semicolon or use Text-to-Columns wizard.
  6. 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 to C:\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; Now uses locale-dependent formatting.
  • Convert numbers with CStr. Always wrap tag reads in CStr(...) to handle type changes gracefully.
  • Free COM objects. Set f and ts to Nothing after 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.

Back to blog