Export WinCC Tag Data to CSV Using VBScript
This lab targets export wincc tags csv vbscript with copy-ready examples, expected results and diagnostic guidance.
1. Design a Stable CSV Format
Choose a delimiter, fixed column order, ISO-style timestamp and decimal convention. Write a header once and escape any text that may contain the delimiter, quote or line break.
2. Read WinCC Tags before Export
Dim tempTag, pressureTag
Set tempTag = HMIRuntime.Tags("Demo_Temperature")
Set pressureTag = HMIRuntime.Tags("Demo_Pressure")
tempTag.Read
pressureTag.Read
3. Append a Timestamped CSV Row
Dim fso, fileObject, filePath, rowText
filePath = "C:\WinCC_Reports\process_log.csv"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists("C:\WinCC_Reports") Then
fso.CreateFolder "C:\WinCC_Reports"
End If
Set fileObject = fso.OpenTextFile(filePath, 8, True)
rowText = Year(Now) & "-" & Right("0" & Month(Now), 2) & "-" & _
Right("0" & Day(Now), 2) & " " & Time & ";" & _
CStr(tempTag.Value) & ";" & CStr(pressureTag.Value)
fileObject.WriteLine rowText
fileObject.Close
Set fileObject = Nothing
Set fso = Nothing4. Prevent Duplicate or Uncontrolled Exports
Trigger the export from an explicit operator event or a suitably slow scheduled action. Use a completion tag or file-level strategy if overlapping calls are possible. Do not write to an unavailable network share from a fast cyclic trigger.
5. CSV Export Troubleshooting
| Problem | Action |
|---|---|
| Permission denied | Grant the Runtime account approved write access to the exact folder |
| File locked | Close Excel or use a separate timestamped output file |
| Wrong decimal/date format | Format values explicitly and document delimiter/locale assumptions |
| Missing rows | Trace trigger execution and verify the action is activated in Runtime |
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.
