Overview: Why Move From CSV to Native Excel Reports
WinCC V7.0 ships with a built-in report designer that defaults to comma-separated values (CSV) when the runtime job runs without a layout configured for the spreadsheet program. CSV is fast, but operations teams, quality engineers, and customers typically want a real Microsoft Excel workbook with frozen header rows, formula columns, formatted timestamps, and per-shift worksheets. The transition from CSV to XLS/XLSX in WinCC V7.0 is not a single property change; it requires either activating the Excel print job in the report designer, or driving Excel from a VB Script through OLE automation. This article documents the script-based approach used in the field, the button wiring on the SCADA picture, and the archive queries that fetch historical tag values between a configurable start time and end time.
The script-based approach is preferred over the print job approach when:
- The customer wants interactive Excel features (formulas, charts, conditional formatting, multiple sheets).
- The runtime workstation does not have a full Microsoft Office installation, or the print job fails on locked-down servers.
- You need to combine live WinCC tag values with historical archive values in the same workbook.
- The button on the SCADA picture must launch a workbook the operator can edit, save, and e-mail.
Throughout this reference the WinCC project is assumed to be a single-server or client-server project running on Windows 7 / Server 2008 R2 or later with WinCC V7.0 SP3 or later. The host must have Microsoft Excel 2007 / 2010 / 2013 installed; 32-bit Office is recommended because the WinCC V7.0 runtime is a 32-bit process and a 32-bit script against 64-bit Excel raises ActiveX component cannot create object errors.
Prerequisites and Software Requirements
Before writing the first line of script, verify the following components are present on the engineering station, the WinCC server, and every WinCC client that needs to run the report:
- WinCC V7.0 (any Service Pack from SP1 onward). Open WinCC Explorer and check the About box for the exact build, e.g. "WinCC V7.0 + SP3 Update 6". The build string matters because the SQL archive schema changed between SP2 and SP3, and OLE DB queries written for one will not work on the other.
-
Microsoft Excel 2007 / 2010 / 2013 (32-bit). The script uses late binding by default so it does not require referencing the Excel object library at design time, but late binding is fragile if Office updates swap the CLSID. The mid-ground is early binding to
Microsoft Excel 14.0 Object Library(Excel 2010) and re-compiling when the Office version is upgraded. - VB Script runtime (msvbvm60.dll / scrrun.dll). WinCC V7.0 installs this automatically. Do not block the script with an anti-virus product that strips WSH.
- MDAC 2.8 or later (or the modern Windows Data Access components). Required for ADODB.Connection, ADODB.Recordset, and the WinCC OLE DB provider.
-
SQL Native Client 2005 / 2008 / 2012 matching the SQL Server instance that WinCC uses for the Tag Logging archive. The runtime archive database is named
CC_<ServerName>_<ProjectName>_Rby default. - Operator authorization level configured in User Administrator. The button event should be limited to operators with the "Report" or higher level to prevent accidental generation of large workbooks during commissioning.
WinCC V7.0 Report Architecture
To write a working export script you need to know which data source the script will read. WinCC V7.0 splits runtime data into three reservoirs:
| Reservoir | Underlying store | Access mechanism | Typical use in reports |
|---|---|---|---|
| Process tags (live) | WinCC internal memory | HMIRuntime.Tags, SmartTags, or the OLE DB WinCC Runtime Database view | Current values, alarms, "report generated at" stamps |
| Tag Logging fast / slow | Microsoft SQL Server (compressed) | OLE DB provider "WinCC OLE DB Provider 1.0" (CLSID WinCCOLEDBProvider.1) | Historical trend values, time-range tables, batch records |
| Alarm Logging | Microsoft SQL Server (compressed) | Same OLE DB provider, different view | Alarm history, operator action audit |
The OLE DB provider is registered when WinCC V7.0 installs. Verify it from the registry:
HKEY_CLASSES_ROOT\WinCCOLEDBProvider.Connect\CLSID
HKEY_LOCAL_MACHINE\SOFTWARE\Siemens\WinCC\SQL\Connectivity
The connection string that the report script will use is:
Provider=WinCCOLEDBProvider.1;
Catalog=CC_<Server>_<Project>_R;
Data Source=<ServerName>\WinCC;
User Id=<WinCCUser>;
Password=<WinCCPassword>;
For local execution from a button the catalog and data source can be the same machine. The user needs rights on the Tag Logging archive, which in WinCC V7.0 means membership in the local group SQLServer2005MSSQLUser$<ComputerName>$<WINCC_INSTANCE> or the equivalent in the active SQL Server version.
The WinCC OLE DB Query Language
The WinCC OLE DB provider exposes a SQL-like language tailored to archives. The three table identifiers that the script will use are:
| Identifier | Meaning | Columns |
|---|---|---|
| TAG:R:<TagName> | Raw values of a single process tag from the Tag Logging archive | TIMESTAMP, REALVALUE, QUALITY, MS, TYPE |
| TAG:L:<TagName> | Last (current) value of the tag | REALVALUE, QUALITY |
| ALGVIEW:<ArchiveName> | Alarm Logging view of a single archive | TIMESTAMP, MS, STATE, ACK, TEXT1..TEXT10 |
Standard SQL clauses (WHERE, BETWEEN, ORDER BY) are supported. The WinCC-specific clauses that distinguish the provider are:
-
SAMPLING PERIOD n- returns one row per n milliseconds, useful for downsampling. -
AGGREGATION <function>- applies MAX, MIN, AVG, SUM, COUNT to REALVALUE before sampling. -
ROWCOUNT n- hard limit on the number of returned rows.
For example, a 24-hour temperature trend at 1-minute average:
SELECT TIMESTAMP, AVG(REALVALUE) AS AvgTemp
FROM TAG:R:'Line1_Temperature'
WHERE TIMESTAMP BETWEEN '2024-01-15 06:00:00' AND '2024-01-16 06:00:00'
GROUP BY TIMESTAMP
SAMPLING PERIOD 60000
ROWCOUNT 2000
YYYY-MM-DD HH:MM:SS regardless of the operator locale. Passing the timestamp in a regional format such as MM/DD/YYYY HH:MM:SS is the most common reason a "valid" window returns zero rows.Choosing the Reporting Method
Three methods are commonly used to move data from WinCC V7.0 into Excel. Pick by the constraints of the customer's site.
| Method | Skill required | Output quality | Operator interaction | Recommended when |
|---|---|---|---|---|
| Built-in Excel print job | Low (configuration only) | Rigid, fixed layout | None - runs on schedule | No customer-specific layout; report runs unattended at end of shift |
| VB Script with OLE automation | Medium (WinCC scripting + Excel COM) | Fully customizable | Button on picture, can edit/save the file | Customer wants the workbook interactive, formulas, multiple tabs, or a single-click download |
| Third-party add-on (RBSReport, WinCC Web Navigator, etc.) | Low to medium | Customizable templates | None or button | Site policy forbids Office on the SCADA station; report server handles Excel out of process |
The rest of this document covers the VB Script method in depth, with notes on RBSReport at the end.
Method 1 - VB Script With OLE Automation to Excel
The VB Script lives in the WinCC Graphics Designer picture. The picture contains four input/output objects: a start time, an end time, a duration label, and a "Generate" button. When the operator presses "Generate" the script runs the export.
Picture-Level Object Model
Create the following I/O field objects on the picture:
| Object | Object name (WinCC) | Type | Linked tag | Purpose |
|---|---|---|---|---|
| Start time | tStart | I/O field, output/input, format "yyyy-MM-dd HH:mm:ss" | Internal tag Report_StartTime (String) |
Operator sets the window start |
| End time | tEnd | I/O field, output/input, format "yyyy-MM-dd HH:mm:ss" | Internal tag Report_EndTime (String) |
Operator sets the window end |
| Duration | tDur | I/O field, output only | None - calculated in C action | Displays End - Start in hours |
| Generate | btnGen | Button | None | Triggers the export script |
Add a C action to the duration field to update every second:
/* Duration calculation - C action behind tDur output */
{
double dStart = atof(GetTagChar("Report_StartTime"));
double dEnd = atof(GetTagChar("Report_EndTime"));
double dDur = (dEnd - dStart) / 3600.0;
SetPropChar(lpszPictureName, "tDur", "OutputValue", dDur);
return dDur;
}
For a pure VB approach without C, drop the C action and compute the duration in the button script instead.
Excel Object Library Choice
There are two binding strategies:
- Early binding: add "Microsoft Excel 14.0 Object Library" (or whatever matches the installed Office) to the script environment. Faster, IntelliSense works in the IDE, but the script breaks if the office version is upgraded.
-
Late binding: instantiate the Excel application with
CreateObject("Excel.Application"). The script survives Office upgrades but every constant has to be its numeric value (e.g.xlContinuous = 1).
For a production WinCC V7.0 project that runs on a fixed image, use early binding. For a project that ships to multiple customer sites, use late binding. The example below uses late binding so it runs unmodified against Excel 2007 / 2010 / 2013 / 2016.
Main Export Script (Late Binding)
Place this VB Script in the button's Mouse click event, configured to run as a VBS action:
'==========================================================================
' WinCC V7.0 - Excel report from Tag Logging archive
' Trigger: btnGen mouse click
'==========================================================================
Option Explicit
Const EXCEL_PATH_TEMPLATE = "C:\WinCC_Reports\Templates\ShiftReport.xltx"
Const EXCEL_PATH_OUTPUT = "C:\WinCC_Reports\Out\"
' WinCC OLE DB connection
Const WINCC_OLESERVER = "WinCCOLEDBProvider.1"
Dim sStart, sEnd
Dim oExcel, oBook, oSheet
Dim oConn, oRS
Dim sConn, sSQL
Dim iRow, iCol
Dim fso
' ---------- 1. Read the time window from the I/O fields ----------
sStart = HMIRuntime.Screens("ReportScreen").ScreenItems("tStart").OutputValue
sEnd = HMIRuntime.Screens("ReportScreen").ScreenItems("tEnd").OutputValue
If sStart = "" Or sEnd = "" Then
MsgBox "Enter start and end time first.", vbExclamation, "Report"
Exit Sub
End If
If CDate(sEnd) <= CDate(sStart) Then
MsgBox "End time must be greater than start time.", vbExclamation, "Report"
Exit Sub
End If
' ---------- 2. Build OLE DB connection string ----------
sConn = "Provider=" & WINCC_OLESERVER & ";" & _
"Catalog=CC_" & HMIRuntime.ComputerName & "_" & _
HMIRuntime.ProjectName & "_R;" & _
"Data Source=" & HMIRuntime.ComputerName & "\WinCC"
' ---------- 3. Open Excel with the customer template ----------
Set fso = CreateObject("Scripting.FileSystemObject")
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.DisplayAlerts = False
oExcel.ScreenUpdating = False
If fso.FileExists(EXCEL_PATH_TEMPLATE) Then
Set oBook = oExcel.Workbooks.Add(EXCEL_PATH_TEMPLATE)
Else
Set oBook = oExcel.Workbooks.Add()
oBook.Sheets(1).Name = "ShiftData"
End If
Set oSheet = oBook.Sheets(1)
' ---------- 4. Write the report header ----------
With oSheet
.Cells(1, 1).Value = "Process report"
.Cells(1, 1).Font.Size = 14
.Cells(1, 1).Font.Bold = True
.Range("A1:D1").Merge
.Cells(2, 1).Value = "Start time:"
.Cells(2, 2).Value = sStart
.Cells(3, 1).Value = "End time:"
.Cells(3, 2).Value = sEnd
.Cells(4, 1).Value = "Duration (h):"
.Cells(4, 2).Value = Round((CDate(sEnd) - CDate(sStart)) * 24, 3)
.Cells(2, 1).Font.Bold = True
.Cells(3, 1).Font.Bold = True
.Cells(4, 1).Font.Bold = True
End With
' ---------- 5. Column headers (row 6) ----------
Dim tags
tags = Array("Line1_Temperature", "Line1_Pressure", "Line1_Flow")
oSheet.Cells(6, 1).Value = "Timestamp"
oSheet.Cells(6, 2).Value = tags(0)
oSheet.Cells(6, 3).Value = tags(1)
oSheet.Cells(6, 4).Value = tags(2)
oSheet.Range("A6:D6").Font.Bold = True
oSheet.Range("A6:D6").Interior.Color = RGB(200, 200, 200)
' ---------- 6. Query Tag Logging archive via OLE DB ----------
Set oConn = CreateObject("ADODB.Connection")
oConn.ConnectionString = sConn
oConn.CursorLocation = 3 ' adUseClient
oConn.Open
iRow = 7
Dim tag, i, colOffset
For Each tag In tags
For i = 0 To UBound(tags)
If LCase(tags(i)) = LCase(tag) Then
colOffset = 2 + i
Exit For
End If
Next
sSQL = "SELECT TIMESTAMP, REALVALUE, QUALITY " & _
"FROM TAG:R:'" & tag & "' " & _
"WHERE TIMESTAMP BETWEEN '" & sStart & "' AND '" & sEnd & "'"
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, oConn, 1, 3 ' adOpenKeyset, adLockOptimistic
Do While Not oRS.EOF
oSheet.Cells(iRow, 1).Value = CDate(oRS.Fields("TIMESTAMP").Value)
oSheet.Cells(iRow, 1).NumberFormat = "yyyy-mm-dd hh:mm:ss"
oSheet.Cells(iRow, colOffset).Value = oRS.Fields("REALVALUE").Value
oSheet.Cells(iRow, colOffset).NumberFormat = "0.00"
iRow = iRow + 1
oRS.MoveNext
Loop
oRS.Close
Next
oConn.Close
' ---------- 7. Apply formatting and save ----------
oSheet.Columns("A:D").AutoFit
oSheet.Range("A6:D" & iRow - 1).Borders.LineStyle = 1 ' xlContinuous
Dim sFile
sFile = EXCEL_PATH_OUTPUT & "Report_" & _
Replace(Replace(Now, ":", "-"), "/", "-") & ".xlsx"
oBook.SaveAs sFile, 51 ' xlOpenXMLWorkbook (xlsx)
oExcel.ScreenUpdating = True
' Leave Excel visible so the operator can verify; oExcel.Quit is intentionally
' omitted if you want a non-blocking export.
Set oConn = Nothing
Set oRS = Nothing
Set oSheet = Nothing
Set oBook = Nothing
Set oExcel = Nothing
Set fso = Nothing
SELECT TIMESTAMP, MAX(CASE WHEN TAGNAME = '...' THEN REALVALUE END) ... GROUP BY TIMESTAMP. That requires T-SQL against the underlying SQL Server, which means using the SQL Server Native Client provider instead of the WinCC OLE DB provider. See the variant in the next section.Variant - Side-By-Side Rows With SQL Server Native Client
The WinCC OLE DB provider returns one row per archive entry per tag, so the data lands in stacked blocks. To get one row per timestamp with all tags in columns, connect to the runtime database directly with the SQL Server provider and pivot the result.
' ---------- Side-by-side query via SQL Native Client ----------
Const SQL_NATIVE = "SQLNCLI10" ' 2008 native client; use SQLNCLI11 for 2012+
Dim sConn2
sConn2 = "Provider=" & SQL_NATIVE & ";" & _
"Data Source=" & HMIRuntime.ComputerName & "\WinCC;" & _
"Initial Catalog=CC_" & HMIRuntime.ComputerName & "_" & _
HMIRuntime.ProjectName & "_R;" & _
"Integrated Security=SSPI;"
Set oConn = CreateObject("ADODB.Connection")
oConn.ConnectionString = sConn2
oConn.Open
' WinCC Tag Logging tables follow the naming convention
' TLG_<TagName>_F (fast) and TLG_<TagName>_S (slow)
Dim sSQL2
sSQL2 = "SELECT a.TIMESTAMP, a.REALVALUE AS Temp, " & _
" b.REALVALUE AS Pres, c.REALVALUE AS Flow " & _
"FROM dbo.TLG_Line1_Temperature_F a " & _
"LEFT JOIN dbo.TLG_Line1_Pressure_F b ON a.TIMESTAMP = b.TIMESTAMP " & _
"LEFT JOIN dbo.TLG_Line1_Flow_F c ON a.TIMESTAMP = c.TIMESTAMP " & _
"WHERE a.TIMESTAMP BETWEEN '" & sStart & "' AND '" & sEnd & "' " & _
"ORDER BY a.TIMESTAMP"
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL2, oConn, 1, 3
iRow = 7
oSheet.Cells(6, 1).Value = "Timestamp"
oSheet.Cells(6, 2).Value = "Temperature"
oSheet.Cells(6, 3).Value = "Pressure"
oSheet.Cells(6, 4).Value = "Flow"
Do While Not oRS.EOF
oSheet.Cells(iRow, 1).Value = CDate(oRS.Fields("TIMESTAMP").Value)
oSheet.Cells(iRow, 1).NumberFormat = "yyyy-mm-dd hh:mm:ss"
oSheet.Cells(iRow, 2).Value = oRS.Fields("Temp").Value
oSheet.Cells(iRow, 3).Value = oRS.Fields("Pres").Value
oSheet.Cells(iRow, 4).Value = oRS.Fields("Flow").Value
iRow = iRow + 1
oRS.MoveNext
Loop
oRS.Close
oConn.Close
REALVALUE for 32-bit float. Earlier service packs sometimes expose a VALUE column. Confirm with SELECT TOP 1 * FROM dbo.TLG_Line1_Temperature_F before deploying the script.Wiring the SCADA Buttons
WinCC V7.0 ties VB Script to events on a Graphics Designer object. To attach the script to the Generate button:
- Open the report picture in Graphics Designer.
- Right-click btnGen and select Properties > Events > Mouse > Click.
- In the action picker choose VB Action and paste the script body. WinCC will compile the script when the picture is saved; the runtime supports
Option Expliciteven if the editor hides it. - Click the Authorization tab and set the operator level that may trigger the report (typically level 4 - "Reporting").
- For runtime loading time, compile the picture: File > Check Consistency then save and download to the runtime station.
- Open the picture in WinCC Runtime, press Generate, and confirm the workbook opens in Excel.
To attach the duration calculation to the I/O field output, the recommended pattern is a global C action scheduled on a 1 s cycle that writes the duration string into a tag; the field has its Output property bound to that tag. This avoids the C action being lost when the picture is closed.
Method 2 - Built-In Excel Print Job (No Script)
If scripting is too heavy for the maintenance team, the report designer can produce an XLS file without any custom code. The catch is that the layout is fixed and there is no operator interaction.
- Open WinCC Explorer > Report Designer > Page Layout.
- Select the print job (e.g. ReportFileStateLog).
- On the Properties tab, set Output format to RTF-File if you want rich text or XLS if a flat Excel file is acceptable.
- Add the required archive columns to the layout, then schedule the print job with the Time Base set to Daily 06:00 for shift hand-over.
- Trigger the print job from a button using a C action that calls
RP_Printwith the job name.
Customers who insist on a "click a button and the workbook opens" experience are not satisfied with the print job. For them, the script approach is the answer.
Method 3 - Third-Party Add-On: RBSReport
RBSReport, the third-party add-on mentioned in the field report, is a WinCC plug-in that runs as a Windows service and can render scheduled and on-demand reports to XLS / XLSX / PDF. The product is published at www.rbsreport.com. Compared with the in-house script:
- Pros: no Office install on the SCADA station, built-in scheduling, built-in e-mail distribution, native support for archive pivots.
- Cons: third-party license cost, version coupling with each WinCC service pack, and the report designer is a separate tool that has to be learned in addition to WinCC.
For customers that need a sustainable shift-reporting solution with operator self-service and e-mail delivery, RBSReport is worth evaluating. For a one-off report that has to be in place next week, the VB Script approach delivers faster.
Performance and Archive Considerations
A poorly designed report can lock the runtime database. The rules below are field-proven on multi-thousand-tag WinCC V7.0 plants.
- Bound the time window. The Tag Logging archive is compressed with a swing buffer; a 24 h window on a 100 ms tag can still return millions of rows. The button script should refuse a window longer than 31 days.
-
Use server-side aggregation. The WinCC OLE DB provider supports a
SAMPLING PERIODclause. For trend lines, ask for 1 min averages instead of raw values:SELECT TIMESTAMP, AVG(REALVALUE) FROM TAG:R:'Line1_Temperature' WHERE TIMESTAMP BETWEEN '2024-01-15 06:00:00' AND '2024-01-16 06:00:00' GROUP BY TIMESTAMP SAMPLING PERIOD 60000 - Run heavy reports from a client, not the server. A WinCC client with the script connected to the server's archive off-loads the CPU from the runtime.
- Excel is single-threaded for VBA work. If the workbook needs formulas, fill them after the data is in (in a separate post-processing step) and only on a copy of the file. Forcing Excel to recalc while the script still has a reference to the workbook hangs the process.
-
Open Excel out of process for long reports.
oExcel.Visible = False, save withoBook.SaveAs, thenoBook.Close FalseandoExcel.Quit. The operator gets a pop-up only when the file is on disk, which keeps the SCADA picture responsive. -
Clean up COM objects. The last
Set oExcel = Nothingline is not optional. Skipping it leaves a phantomEXCEL.EXEin Task Manager and the next export fails with The server threw an exception. - Pre-create the output directory in the project startup script. If the directory is missing the SaveAs call throws Path not found and Excel stays open holding a temp file.
Common Edge Cases and Pitfalls
| Edge case | What happens | Defensive code |
|---|---|---|
| Operator enters dd.mm.yyyy in the I/O field | OLE DB rejects the timestamp, returns zero rows | Normalize with FormatDateTime(CDate(sStart), "yyyy-mm-dd hh:nn:ss") before building the SQL string |
| Tag Logging is configured with a swap segment and the active segment is full | Archive queries stall while SQL Server rotates the segment | Schedule heavy reports outside the swap window or wrap the query in a TIMEOUT property on the ADODB connection |
| Daylight saving transition inside the window | One row appears twice or is missing because the local clock jumped | Force the report to UTC by adding DateAdd("h", ZoneBias, ts) on read-back, and document that the window is in UTC |
| Operator presses Generate twice in quick succession | Two Excel instances fight for the same output file and one SaveAs fails | Set a global boolean bReportRunning in the picture and ignore the second press while the first is active |
| Tag was renamed after archive creation | TAG:R query returns Invalid tag name | Wrap the query in On Error Resume Next + Err.Number check; log the tag name and skip |
| Template file is checked into source control as read-only | Excel cannot save changes and silently keeps the original | Copy the template to a writable scratch path with fso.CopyFile before opening |
Verification and Acceptance Test
After the script is deployed, run the following acceptance checklist before hand-over:
- Open the picture on a runtime client and press Generate with a 1 min window. The workbook should open in Excel with three columns and a row count equal to the number of archived values in the window (rounded to the archive cycle).
- Open the workbook, verify the header block (Start / End / Duration) and that the timestamps in column A are sorted ascending.
- Repeat the test with a 24 h window on a 1 s tag. The export should complete in under 30 s on a quad-core SCADA client. If it takes more than 2 min, the OLE DB provider is being asked for raw values; switch to
SAMPLING PERIOD. - Trigger the export on a different client. Both outputs should be byte-identical except for the file name (which is timestamp-based).
- Open the SQL profiler trace on the runtime database while the export runs and confirm the OLE DB provider issues a single
SELECTper tag. A flood of small queries indicates the script is reading values one at a time and must be re-written with a singleRecordsetread. - Close Excel with the workbook still open, then re-open it from Windows Explorer. The file should display the same data. If the file is empty, the script saved before the data write completed; move the
SaveAscall to the very end of the script. - Restart the WinCC runtime and re-run the export. The same data must appear; if not, the script depends on a session-bound ADODB connection that the runtime did not re-open.
Troubleshooting Matrix
| Symptom | Root cause | Fix |
|---|---|---|
"ActiveX component can't create object" on CreateObject("Excel.Application")
|
Office is 64-bit, WinCC process is 32-bit (or vice versa) | Install 32-bit Office; WinCC V7.0 runtime is 32-bit only |
| "Provider cannot be found" on OLE DB connect | WinCC OLE DB provider not registered on the runtime station | Reinstall WinCC Runtime on the station or run regsvr32 WinCCOleDBProv.dll |
| Export returns zero rows for a valid window | Operator's WinCC user has no read right on the archive | Add the user to the SQL Server login of the runtime DB, or use Integrated Security=SSPI from a client that is logged in as a WinCC administrator |
| Timestamps off by one hour in the workbook | WinCC archive stored in UTC, Excel formatted in local time without offset | Either configure WinCC Tag Logging to store local time, or apply DateAdd("h", 1, timestamp) in the script |
| Excel crashes when the picture is closed | COM object not released, or the picture's unload kills the script thread mid-recordset read | Wrap the body in a single sub that sets every Set obj = Nothing at the end, and avoid using On Error Resume Next in the cleanup section |
"File not found" on SaveAs
|
Target directory missing or the WinCC runtime user has no write right | Pre-create the directory on first run, grant Authenticated Users write on the output folder |
| Button does nothing on click | Authorization level too high for the operator, or the action was attached to Mouse Down instead of Mouse Click | Set the button's authorization to "Reporting" or use the operator's own level, and re-attach to Mouse Click |
| Generated file is 0 KB | SQL query returned an empty recordset because the timestamp string format did not match the locale | Use FormatDateTime(Now, vbGeneralDate) and pass the timestamp in YYYY-MM-DD HH:MM:SS format |
| Excel stays in Task Manager after the script ends |
oExcel.Quit missing or failed before oExcel = Nothing
|
Force-quit with oExcel.Quit then Set oExcel = Nothing; in extreme cases, kill EXCEL.EXE from a watchdog |
| File is locked when re-opening for the second export | Previous export left the workbook open with the read-only flag set | Set oExcel.DisplayAlerts = False and call oBook.Close False before oExcel.Quit
|
Deployment and Migration Notes
When the script is moved from the engineering station to a customer runtime, observe the following migration steps:
- Export the picture from Graphics Designer on the engineering station (File > Export > WinCC Picture).
- On the target runtime, install the same Office build and the same SQL Native Client build. Mixed Office versions on a multi-server WinCC project are the leading cause of late-binding errors on the operator client but not the engineering client.
- Re-create the internal tags
Report_StartTimeandReport_EndTimein the target project if they were not exported with the picture. - Grant the WinCC runtime user read on the SQL Server runtime database. The minimum permission is db_datareader on
CC_<Server>_<Project>_R. - Pre-create
C:\WinCC_Reports\Outand the Templates subfolder. Copy the customer's ShiftReport.xltx template to the Templates folder. - Test the export with the same 1 min window used in the engineering acceptance test before commissioning the picture on the operator client.
For customers upgrading from WinCC V6.2 to V7.0 the script is mostly portable. The two changes that are commonly required are: the catalog suffix changed from _R in V6.2 to the same _R in V7.0 (no change) but the default archive column VALUE was renamed to REALVALUE; and the runtime now requires the OLE DB provider registration step that was implicit in V6.2.
FAQ
How do I add a reference to the Excel object library in WinCC V7.0's VB Script editor?
Open the picture in Graphics Designer, right-click the script action, choose Edit VB Action, then on the menu Tools > References and tick "Microsoft Excel 14.0 Object Library" (or the version installed). For late binding, no reference is required; instantiate with CreateObject("Excel.Application").
Which Excel object library version matches my Office install?
Excel 2007 ships library version 12.0, Excel 2010 is 14.0, Excel 2013 is 15.0, Excel 2016 is 16.0, Office 365 is also 16.0. Pick the library that matches the youngest Office version that the script will run against. To keep the script portable across multiple customer sites, use late binding.
How do I query historical tag values from the WinCC V7.0 Tag Logging archive?
Open an ADODB connection to the runtime database with the WinCC OLE DB provider (CLSID WinCCOLEDBProvider.1) and execute a SELECT TIMESTAMP, REALVALUE, QUALITY FROM TAG:R:'TagName' WHERE TIMESTAMP BETWEEN '...' AND '...' query. For long windows, add GROUP BY TIMESTAMP SAMPLING PERIOD 60000 to receive 1-minute averages.
How do I call a VB Script from a WinCC button?
Right-click the button, choose Properties > Events > Mouse > Click, set the action type to VB Action, and paste the script. Set the authorization on the same dialog so only operators with reporting rights can trigger the export.
Can I use Office 2016 / 2019 / 365 with WinCC V7.0 on Windows 10?
Yes, with the same caveat as older Office versions: the Office install must be 32-bit to match the 32-bit WinCC process, and the script should use late binding (or be re-bound to the 16.0 object library after the upgrade). Siemens officially supports Office 2016 with WinCC V7.0 SP3 Update 6 and later; for SP2 and earlier, Office 2010 is the highest tested combination.