WinCC Explorer · VBScript · Practical Tutorial

Export WinCC Tag Data to CSV Using VBScript

Export WinCC Runtime tag values to timestamped CSV files using VBScript and FileSystemObject, with validation and file-error handling.

Lab Overview

WinCC VBS Lab 5Estimated time: 75 minutesDifficulty: Intermediate

Prerequisites / What You’ll Need

  • Backed-up WinCC Explorer test project
  • Graphics Designer and Global Script VBS access
  • Internal test tags and Runtime diagnostics

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.

Safety: Test on internal tags or an approved simulation system. Do not bypass PLC permissives, interlocks, user authorization or plant change control.

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 = Nothing
Expected output: One new semicolon-delimited line appears with timestamp, temperature and pressure.

4. 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

ProblemAction
Permission deniedGrant the Runtime account approved write access to the exact folder
File lockedClose Excel or use a separate timestamped output file
Wrong decimal/date formatFormat values explicitly and document delimiter/locale assumptions
Missing rowsTrace trigger execution and verify the action is activated in Runtime

Hands-On Verification Lab

Hands-on
1

Prepare a controlled test

Create only the internal tags, folders or disposable database rows required by this tutorial.

The test scope is isolated and documented.
2

Run the smallest example

Execute one operation and inspect WinCC diagnostics before expanding the script.

The expected value, file, object or database result appears once.
3

Test a failure path

Use a safe backup copy to test an invalid tag, path or disposable input.

The script records a useful error and cleans up without an uncontrolled action.

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.

Get the WinCC VB Scripting syllabus

Share your details and a Softwell advisor will contact you with training options.

Build reliable WinCC VBScript projects

Join practical online, classroom or corporate training.

Request Course Details
Verified learning pathway

Discuss WinCC VB Scripting Training

Explore practical WinCC VBS, SCADA, SQL reporting and industrial automation training options.

Content reviewed: 4 August 2026

☎ Call WhatsApp ✉ Email Enquire Now