Integrating Siemens WinCC SCADA with Microsoft Excel using VBScript enables powerful automation for real-time data handling, historical logging, and report generation. This functionality is essential for engineers and system integrators who need to streamline SCADA data analysis, simplify recordkeeping, or generate formatted print reports without manual intervention.
In this comprehensive guide, you'll learn how to read tag values from WinCC, write data into Excel workbooks, and print log reports directly from Excel using VBScript scripts executed within the SCADA environment. These scripts can be triggered on events such as button clicks or timed intervals, making them ideal for daily log creation or shift-based reporting. in this article We'll cover:
Open Tag Management and insert the tags report_tag_1, report_tag_2, and report_tag_3. Use the Floating data type as shown below.
Open the Graphics Designer in Siemens WinCC and design your SCADA screen for Excel data interaction. Add three Input/Output field elements and assign the tags report_tag_1, report_tag_2, and report_tag_3 which were previously created in Tag Management. These fields will be used to display live data from the SCADA system and allow operators to input values if needed.
Next, add three functional buttons to the screen interface:
To enable automatic logging of SCADA tag values into Excel, open the Global VBScript Editor in Siemens WinCC. Create a new script or edit an existing one, and insert the following VBScript code. This script writes the values of report_tag_1, report_tag_2, and report_tag_3 into a specified Excel file. If the Excel file does not exist at the specified path, the script will automatically create it and then log the tag data into the next available row.
Before using this script in runtime, ensure that:
To retrieve data from an Excel file and populate SCADA tags in Siemens WinCC, open the Global VBScript Editor and add the script shown below. This VBScript reads values from a specific row and column in an existing Excel sheet and assigns them to the tags report_tag_1, report_tag_2, and report_tag_3.
Before using this script, make sure that:
To automate PDF report generation from Siemens WinCC SCADA, use VBScript within the Global Script Editor. The VBScript below opens an existing Excel file, defines a print area, and silently exports the content as a PDF file to a predefined path. This method does not use a print dialog and relies on Excel’s built-in PDF export functionality (Excel 2007 or later).
Before executing the script, ensure the following prerequisites are met:
Open Graphics Designer and open the same screen created earlier with the input/output fields and control buttons. Select the Read button on the screen, and in the Properties window, go to the Events tab.
Choose the Mouse Click event and assign a C Action. In the script area, call the global VBScript subroutine that you created for reading Excel data into WinCC tags. Example:
Call ReadTagValuesFromExcel()
This ensures that when the operator clicks the "Read" button on the screen, the SCADA system will automatically open the Excel file, read the tag values from predefined cells, and update the associated screen tags accordingly.
In the Graphics Designer, locate the same SCADA screen and select the Write button. Navigate to the Events tab in the properties pane, then choose the Mouse Click event.
Add a C Action that calls the global script for writing tag values to Excel:
Call WriteTagValuesToExcel()
When this button is clicked during runtime, the script writes the current values of the SCADA screen tags to the Excel file specified in the script. This can be useful for logging operator input, setpoints, or manual entries into a structured report.
To allow operators to generate PDF reports directly from the SCADA screen, select the Print or Export to PDF button in Graphics Designer. Under the Events tab, select the Mouse Click event and add a C Action.
Use the following script call to run the global subroutine that exports the Excel log to a PDF file:
Call ExportExcelSheetAsPDF()
This will trigger the VBScript that opens the Excel file, defines the print area, and exports it to a predefined PDF path without any user interaction. It’s ideal for shift-wise reports or audit-ready logs.
To verify the full integration of WinCC SCADA with Excel using VBScript, test each button during runtime using the following file paths:
This button loads tag values from Excel into the SCADA screen. At runtime:
This button saves current WinCC tag values into Excel. To test:
This button exports the Excel file to a PDF format without opening any dialog box. To test:
If the PDF doesn't appear, ensure Microsoft Excel 2007 or later is installed and the path exists. Also confirm no Excel process is left running in the background.