<!-- Softwell WinCC VBScript 20-Part Tutorial · Blog 18 · updated 2026-08-29 --> Generate Excel Reports from WinCC Using VBScript | Softwell
WinCC Explorer · VBScript · Practical Tutorial

Generate Excel Reports from WinCC Using VBScript

Generate formatted Excel production reports from WinCC tags using VBScript, Excel automation, timestamps and safe object cleanup.

Lab Overview

WinCC VBS Lab 6Estimated time: 90 minutesDifficulty: Intermediate-Advanced

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: Excel 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

Loops, error handling and a clear source dataset from tags/SQL/CSV. Excel must be installed on the runtime/report PC.

Core concept

Excel COM automation must create objects in a controlled order, write data efficiently, format only what is needed, save deterministically and release every COM object.

SQF practical connection

Generate an SQF production report with timestamp, charge, setpoint/actual values and status columns.

Expected competency

Automate Excel.Application safely and avoid orphaned EXCEL.EXE processes through proper save/close/cleanup.

Generate Excel Reports from WinCC Using VBScript — ArchitectureCode-rendered HTML/CSS architecture; no image file required
WinCC / SQL Data

Collect report dataset

Tags / Recordset
Excel.Application

Create COM server

CreateObject
Workbook

Create/open report file

Workbooks.Add
Worksheet

Write and format cells

Cells(r,c)
Save / Cleanup

SaveAs, Close, Quit, Nothing

Release COM

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.

Generate Excel Reports from WinCC Using VBScript

This lab targets wincc excel report 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. Choose an Excel Automation Architecture

WinCC VBS can automate desktop Excel through COM when Excel is installed on the Runtime station. For unattended or server systems, CSV or a server-side reporting service is often more reliable. Confirm licensing, interactive-session behavior and support requirements.

2. Create a Workbook and Worksheet

Dim excelApp, workbook, worksheet
Set excelApp = CreateObject("Excel.Application")
excelApp.Visible = False
Set workbook = excelApp.Workbooks.Add
Set worksheet = workbook.Worksheets(1)

worksheet.Name = "Process Report"
worksheet.Cells(1, 1).Value = "Timestamp"
worksheet.Cells(1, 2).Value = "Temperature"
worksheet.Cells(1, 3).Value = "Pressure"

Easy TestEasy Test 1 — InputBox + MsgBox

Dialog-first test before launching Excel automation.

Dim ReportName
ReportName = InputBox("Enter report name", "Easy Test 1 — InputBox + MsgBox", "SQF_Process_Report.xlsx")
If ReportName = "" Then
    MsgBox "Test cancelled.", vbInformation, "Excel Quick Test"
Else
    MsgBox "Excel test value received:" & vbCrLf & ReportName & vbCrLf & _
           "Now run the original Excel automation code above.", _
           vbInformation, "Excel Quick Test"
End If

3. Write WinCC Tag Values

Dim tempTag, pressureTag
Set tempTag = HMIRuntime.Tags("Demo_Temperature")
Set pressureTag = HMIRuntime.Tags("Demo_Pressure")
tempTag.Read
pressureTag.Read

worksheet.Cells(2, 1).Value = Now
worksheet.Cells(2, 2).Value = CDbl(tempTag.Value)
worksheet.Cells(2, 3).Value = CDbl(pressureTag.Value)
worksheet.Columns("A:C").AutoFit

Easy TestEasy Test 2 — InputBox + MsgBox

Dialog-first test before launching Excel automation.

Dim ReportName
ReportName = InputBox("Enter report name", "Easy Test 2 — InputBox + MsgBox", "SQF_Process_Report.xlsx")
If ReportName = "" Then
    MsgBox "Test cancelled.", vbInformation, "Excel Quick Test"
Else
    MsgBox "Excel test value received:" & vbCrLf & ReportName & vbCrLf & _
           "Now run the original Excel automation code above.", _
           vbInformation, "Excel Quick Test"
End If

4. Save and Clean Up Excel Correctly

Dim reportPath
reportPath = "C:\WinCC_Reports\ProcessReport.xlsx"

workbook.SaveAs reportPath
workbook.Close False
excelApp.Quit

Set worksheet = Nothing
Set workbook = Nothing
Set excelApp = Nothing

Easy TestEasy Test 3 — InputBox + MsgBox

Dialog-first test before launching Excel automation.

Dim ReportName
ReportName = InputBox("Enter report name", "Easy Test 3 — InputBox + MsgBox", "SQF_Process_Report.xlsx")
If ReportName = "" Then
    MsgBox "Test cancelled.", vbInformation, "Excel Quick Test"
Else
    MsgBox "Excel test value received:" & vbCrLf & ReportName & vbCrLf & _
           "Now run the original Excel automation code above.", _
           vbInformation, "Excel Quick Test"
End If

Close worksheet/workbook references before quitting Excel. Add scoped error handling and cleanup so a failed save does not leave hidden Excel processes running.

5. Excel Report Troubleshooting

ProblemCheck
Cannot create Excel.ApplicationExcel installation, COM registration, bitness and Runtime identity
Workbook cannot saveFolder access, existing locked file and valid extension
Excel.exe remains runningUnreleased worksheet/range/workbook references or skipped cleanup
Automation fails as a serviceUse CSV or a supported server-side report architecture

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 18

Excel report source

SELECT TOP 100
    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
FROM dbo.tblEvent
ORDER BY ID DESC;

Easy TestEasy Test 4 — InputBox + MsgBox

Read/query preview using the SQF running project.

Dim ChargeNo
ChargeNo = InputBox("Enter a Charge Number to understand this query", "Easy Test 4 — InputBox + MsgBox", "CHG-001")
If ChargeNo = "" Then
    MsgBox "Test cancelled.", vbInformation, "Quick Test"
Else
    MsgBox "Query input = " & ChargeNo & vbCrLf & _
           "Run the SQL above against SQF_DB.dbo.tblEvent to see the actual rows.", _
           vbInformation, "SQL Quick Test"
End If
Use bounded queries for predictable reporting and classroom testing.

Build reliable WinCC VBScript projects

Join practical online, classroom or corporate training.

Request Course Details
WinCC VBScript Learning Path 7 of 10

Excel COM report generation: engineering guide

Automate workbook creation, cell formatting and report saving while preventing orphaned Excel processes.

Implementation and commissioning checklist

Practical completion outcome

A formatted test report that saves once, closes cleanly and leaves no Excel.exe process running.

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