<!-- Softwell WinCC VBScript 20-Part Tutorial · Blog 17 · updated 2026-08-29 --> Export WinCC Tag Data to CSV Using VBScript | Softwell
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

Learning Foundation: File Reporting

This page has one defined job in the WinCC VBScript learning path. Master this foundation before using the same concept inside larger SCADA, SQL Server and reporting scripts.

AdvancedWinCC Explorer / Classic WinCCSQF Running Project
Prerequisite

Tag reading, loops, string conversion and error handling.

Core concept

CSV export needs a stable column order, consistent timestamp/text formatting, delimiter-safe values and deterministic file handling.

SQF practical connection

Export SQF_No, ChargeNo, event and process values to a timestamped CSV for quick production analysis.

Expected competency

Create reliable CSV files from WinCC data using FileSystemObject with validation and cleanup.

Export WinCC Tag Data to CSV Using VBScript — ArchitectureCode-rendered HTML/CSS architecture; no image file required
WinCC Tags

Read report values

SQF / Temp / CP
Format

Convert date/numbers/text

CStr / Replace
FSO

Create/open target file

FileSystemObject
CSV Row

Write stable columns

WriteLine
Close / Verify

Release handle and confirm file

Close

Complete WinCC VBScript Learning Path

Use Previous/Next for the recommended practical order, or open any topic below as a reference.

WinCC VB Scripting Training →
Easy Testing Method: Every main code example on this page is followed by a copy-ready InputBox + MsgBox test. Use the dialog version first to understand the result, then move to the original WinCC/SQL code. Database writes and equipment commands are previewed or simulated unless the original example is already intended as a lab action.

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

Easy TestEasy Test 1 — InputBox + MsgBox

Offline tag simulation: useful before connecting the participant PC to WinCC Runtime.

Dim TestValue, ResultText
ResultText = ""
TestValue = InputBox("Enter simulated value for Demo_Temperature", "Easy Test 1 — InputBox + MsgBox", "825.5")
ResultText = ResultText & "Demo_Temperature = " & TestValue & vbCrLf
TestValue = InputBox("Enter simulated value for Demo_Pressure", "Easy Test 1 — InputBox + MsgBox", "TEST")
ResultText = ResultText & "Demo_Pressure = " & TestValue & vbCrLf
MsgBox ResultText & vbCrLf & "Now compare these values with the original HMIRuntime .Read example.", vbInformation, "Tag Read Quick Test"

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

Easy TestEasy Test 2 — InputBox + MsgBox

Confirms the output path before file creation.

Dim FilePath
FilePath = InputBox("Enter CSV file path", "Easy Test 2 — InputBox + MsgBox", "C:\WinCC_Reports\process_log.csv")
If FilePath = "" Then
    MsgBox "Test cancelled.", vbInformation, "CSV Quick Test"
Else
    MsgBox "CSV target:" & vbCrLf & FilePath & vbCrLf & _
           "Run the original code above to create/write the file.", _
           vbInformation, "CSV Quick Test"
End If
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.

SQF Running Project Lab · Blog 17

CSV columns should follow the SQF report model

DT,TM,SQF_No,ChargeNo,Event_From,Event_To,Temp_Set,Temp_Act,Cp_Set,Cp_Act,Oil_Set,Oil_Act,Jacket_Set,Jacket_Act,Fan_Status

Easy TestEasy Test 3 — InputBox + MsgBox

Use a sample value to visualize how the data moves through the project.

Dim TestCharge
TestCharge = InputBox("Enter sample ChargeNo", "Easy Test 3 — InputBox + MsgBox", "CHG-001")
MsgBox "Sample Charge = " & TestCharge & vbCrLf & _
       "Learning flow: WinCC Tags -> VBScript -> SQF_DB.dbo.tblEvent -> Report", _
       vbInformation, "Quick Test"
Keeping the same column order makes SQL, CSV and Excel lessons easier to compare.

Build reliable WinCC VBScript projects

Join practical online, classroom or corporate training.

Request Course Details
WinCC VBScript Learning Path 6 of 10

Reliable CSV data export: engineering guide

Create timestamped CSV output with stable delimiters, validated folders, escaped values and deterministic file cleanup.

Implementation and commissioning checklist

Practical completion outcome

A CSV export that opens correctly in the target reporting tool and records failures without losing Runtime control.

Safety boundary: Validate scripts on a backed-up WinCC training or staging project. PLC safety functions, permissives and interlocks must remain independent of HMI scripting.

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