Scheduling Monthly User Archive Export in WinCC 7.5 with VBS

David Krause15 min read
SiemensTutorial / How-toWinCC
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Scheduling Monthly User Archive Export in WinCC 7.5 with VBS

Exporting a SIMATIC WinCC User Archive once per month looks trivial on a whiteboard, but the WinCC 7.5 scripting environment imposes a hard split: the C editor exposes a full monthly trigger, the VBS editor does not, and VBS Global Actions execute in a picture-less background context that silently breaks any routine copied from a working button click. This reference covers the three supported paths (C Global Action, WinCC/Calendar Scheduler V7.5 SP2, and the Connectivity Pack UAExport sample), the runtime pitfalls that surface when a mouse-click handler is migrated to a scheduled action, and a verified VBS + OLE DB implementation that overwrites cleanly and survives a service-account permission audit.

1. Problem Definition

The standard requirement is to dump a configured User Archive (for example ProcessValues, BatchRecords, ShiftLogs) to a CSV file on the first day of every month at a known time, with no operator interaction, and to overwrite or timestamp the output so the previous month's data is not lost. Two constraints complicate the implementation in WinCC 7.5:

  • VBS lacks a Monthly trigger. The VBS Global Action editor displays a Trigger tab but the radio set is limited to cyclic intervals (default 250 ms, 500 ms, 1 s, 5 s, 10 s, 1 min, 5 min, 10 min, 1 h) and hotkey assignments. There is no Monthly option in the VBS trigger UI.
  • Global Actions run without a picture. Any code that resolves screen items, OLE controls, ActiveX instances, or the UserArchiveControl itself returns Nothing in the background context and raises a runtime error. The WinCC V7.5 manual documents this as a runtime design decision: scheduled actions are deliberately decoupled from the Graphics Runtime so that picture corruption cannot stop a background process.

A working Button »Mouse click« VBS handler that reads HMIRuntime.Screens("Main").ScreenItems("UA") will fail the instant it is moved into a Global Action. The fix is to switch from picture-bound WinCC Controls to headless access through the Connectivity Pack OLE DB provider WinCCOLEDBProvider.1.

2. Prerequisites

  • SIMATIC WinCC V7.5 (or V7.5 SP1 / SP2) installed on the engineering station and on the runtime server.
  • WinCC/Connectivity Pack V7.5 installed on the WinCC server. Required for the WinCCOLEDBProvider.1 OLE DB interface used by the VBS export routine. Reference: WinCC/Connectivity Pack V7.5 - Query for User Archives.
  • WinCC User Archive option licensed and at least one archive configured under »User Archives« in WinCC Explorer with at least one column of type Number, Text, or Date/Time.
  • WinCC/Calendar Scheduler V7.5 SP2 (only for the calendar-based path). Reference: SIMATIC HMI WinCC Calendar Scheduler V7.5 SP2 - System Manual, A5E49472488-AA, section 5.3.
  • A local or UNC destination path with Modify rights for the WinCC runtime service account (typically CCAdmin or the custom service account defined during WinCC setup).
  • WinCC Graphics Runtime running (or WinCC Service Mode enabled) for Global Actions to execute on a headless server.

3. Trigger Capability Matrix

Mechanism Script Type Monthly Trigger Background Execution Picture Object Access License Required
C Global Action ANSI-C Yes (built-in) Yes No Base WinCC
VBS Global Action VBScript No native Yes No Base WinCC
VBS Picture Event VBScript No No Yes Base WinCC
Calendar Scheduler V7.5 SP2 VBScript / C Yes (any recurrence) Yes No Calendar Scheduler option
Windows Task Scheduler External Yes (calendar) External N/A None

Reading the table: if a pure-VBS solution is mandatory, the only first-party answer inside WinCC is the Calendar Scheduler option. C users can stop at the standard C Global Action. Operators that already maintain Windows Task Scheduler jobs on the same server can also drive a ccuaexp.exe-style batch export, but that path is out of scope for the WinCC scripting question.

4. Root Cause: Why a Mouse-Click Script Fails in a Global Action

A VBS Picture event handler executes inside the Graphics Runtime, where HMIRuntime exposes a fully populated object model: Screens, ScreenItems, Tags, Alarms, and any OLE/ActiveX controls that were placed on the active picture. A Global Action executes under GSC Runtime, a separate process that does not load any picture. The picture object hierarchy is replaced with a reduced API: HMIRuntime.Tags works, HMIRuntime.Screens returns an empty collection, and any code that dereferences a screen item raises one of the following runtime errors logged to WinCC_Sys_<server>.log and to the GSC diagnostic window:

  • Object required: 'HMIRuntime.Screens(...)'
  • Variable is undefined: 'ScreenItems'
  • Invalid procedure call or argument
  • ActiveX component can't create object (for OLE controls that require a picture host)

The fix is structural: replace every picture-bound reference with a tag, OLE DB, or WinCC API call that is supported in the Global Action context. The Connectivity Pack FAQ documents the supported access pattern. Reference: Siemens Support Entry 10095491 - How is the data from a user archive filtered, sorted and exported in Runtime?

5. Method 1 - C Global Action with Native Monthly Trigger

The C editor in WinCC 7.5 ships with the full Trigger tab and a Monthly radio option. Configuration steps:

  1. Open WinCC Explorer on the engineering station.
  2. Right-click »Global Script« → »C-Actions« → »New Action«.
  3. Open the new action's properties, switch to the »Trigger« tab.
  4. Enable »Cyclic event« and select »Monthly«.
  5. Set the day-of-month (1..28) and the time of day in 24-hour format (for example, 00:00:05 for an export five seconds after midnight on day 1).
  6. Add a call to the Connectivity Pack C export helper, or write the file directly via fopen / fprintf using the OLE DB equivalent.

The C function from the Connectivity Pack sample (entry 10095491) has the signature:

BOOL UAExport(LPCSTR archiveName, LPCSTR outputFile, LPCSTR filter, LPCSTR sort);

Call example inside the C Global Action body:

UAExport("ProcessValues", "D:\\Exports\\ProcessValues.csv", "", "TimeStamp DESC");

Limitations of UAExport:

  • Does not overwrite an existing file and does not raise an error code. The call returns TRUE and silently leaves the previous file in place.
  • Does not accept a delimiter parameter; the default is locale-dependent. For stable CSVs, post-process the output or use a custom OLE DB writer.
  • Filter and sort strings follow the WinCC User Archive SQL dialect and must reference existing column names.

6. Method 2 - WinCC/Calendar Scheduler V7.5 SP2

The Calendar Scheduler option, described in section 5.3 of the system manual A5E49472488-AA (SIMATIC HMI WinCC Calendar Scheduler V7.5 SP2), adds two components to the WinCC configuration:

  • A Calendar object that holds a list of actions and their schedules.
  • A Calendar Scheduler Service that wakes the configured actions at the scheduled time, even when no picture is open.

Setup procedure:

  1. Install »WinCC/Calendar Scheduler« from the WinCC V7.5 SP2 setup. Restart the WinCC server.
  2. Open the Calendar Scheduler editor from the Windows Start menu or via the WinCC Explorer toolbar.
  3. Create a new Calendar and add an Action. Select the trigger type »Monthly« and set the day-of-month and time.
  4. In the action body, call a VBS routine that uses the OLE DB provider to dump the archive.
  5. Save the configuration and activate runtime. The Calendar Scheduler service starts automatically with the WinCC runtime.

Diagnostic logging: enable »Write diagnostic entries« in the action properties to produce a per-trigger line in CalendarScheduler.log inside the WinCC project directory. Failed actions also log a WinCC alarm.

Service check: confirm »SIMATIC WinCC Calendar Scheduler« is set to Automatic in services.msc. If the service is stopped, monthly actions never fire, and no alarm is raised because the trigger source itself is the service.

7. Method 3 - UAExport Sample (FAQ 10095491)

The FAQ at entry 10095491 ships a ready-made C function named CRT3884_UAExport that wraps the OLE DB call into a single export. It is the fastest way to get a working monthly dump without writing the OLE DB plumbing yourself. The function is delivered as part of the UAExport.zip attachment referenced in the FAQ.

Deployment steps:

  1. Download UAExport.zip from the FAQ attachment section.
  2. Unpack into a directory on the WinCC server, for example C:\WinCC\Scripts\UAExport.
  3. Compile the C source with Visual Studio referencing the WinCC API headers, or use the prebuilt DLL if shipped with the package.
  4. Add the function declaration to the C Global Action that owns the monthly trigger.
  5. Call UAExport(archive, path, filter, sort) from the action body.

Known behavior to handle in your wrapper:

  • No overwrite: existing destination file is left untouched. The function returns TRUE with no error code.
  • No delimiter option: use the locale's default. If the target downstream parser expects comma, the export must be post-processed.
  • Archive must be open: if the archive is closed or locked by another process, the call returns FALSE and writes a line to WinCC_Sys_<server>.log.

8. VBS + OLE DB Implementation (Headless)

The Connectivity Pack manual documents the connection string and SQL syntax for user archives. Reference: WinCC/Connectivity Pack V7.5 - Query for User Archives. The connection string template is:

Provider=WinCCOLEDBProvider.1;Catalog=<Type>;Data Source=.\WinCC

Where <Type> is the archive family, e.g. CC_UAProcessValues for a user archive named ProcessValues. A VBS implementation that works inside a Global Action and writes a clean CSV with a configurable delimiter:

Sub ExportUserArchive(sArchive As String, sFile As String, Optional sDelim As String = ";")
    Dim sCon As String
    sCon = "Provider=WinCCOLEDBProvider.1;Catalog=" & sArchive & ";Data Source=.\WinCC"
    Dim oRs As Object
    Set oRs = CreateObject("ADODB.Recordset")
    oRs.CursorLocation = 3  ' adUseClient
    oRs.Open "SELECT * FROM " & sArchive, sCon, 3, 3
    Dim oFs As Object, oTs As Object
    Set oFs = CreateObject("Scripting.FileSystemObject")
    If oFs.FileExists(sFile) Then oFs.DeleteFile sFile, True
    Set oTs = oFs.OpenTextFile(sFile, 2, True, -1)  ' Unicode
    Dim sLine As String, i As Integer
    sLine = ""
    For i = 0 To oRs.Fields.Count - 1
        sLine = sLine & oRs.Fields(i).Name & sDelim
    Next i
    oTs.WriteLine Left(sLine, Len(sLine) - Len(sDelim))
    Do While Not oRs.EOF
        sLine = ""
        For i = 0 To oRs.Fields.Count - 1
            sLine = sLine & CStr(oRs.Fields(i).Value) & sDelim
        Next i
        oTs.WriteLine Left(sLine, Len(sLine) - Len(sDelim))
        oRs.MoveNext
    Loop
    oTs.Close
    oRs.Close
End Sub

Calling from a Calendar Scheduler action or a C Global Action (with COM init):

Dim sFile : sFile = "D:\Exports\ProcessValues_" & Year(Now) & Right("0" & Month(Now), 2) & ".csv"
Call ExportUserArchive("ProcessValues", sFile, ";")

The Year(Now) & Right("0" & Month(Now), 2) pattern produces filenames like ProcessValues_202501.csv, which makes the overwrite conflict a non-issue and produces an audit trail of monthly snapshots that can be archived to a network share.

9. File-Exists / Overwrite Handling

The UAExport helper does not overwrite and does not raise an error. There are three accepted workarounds, in order of preference:

  1. Timestamped filename as shown above. Recommended; eliminates the conflict entirely and keeps an audit trail.
  2. Pre-delete in the calling wrapper. Use Scripting.FileSystemObject.DeleteFile before the export. The wrapper example above implements this.
  3. Append the day-of-month as a version suffix (e.g. _d01, _d15) for cases where a single archive is exported multiple times per month by different schedules.
Race condition warning: if a network share is the destination and the share is unavailable, the VBS OpenTextFile call raises a runtime error that halts the Global Action. Wrap the open in On Error Resume Next and check Err.Number before continuing, or implement a retry loop with a configurable attempt count.

10. Filter and Sort Expressions

The Connectivity Pack supports a SQL-like syntax against user archives. The SELECT statement accepts * for all columns, a comma-separated list, or a TOP n limiter. WHERE and ORDER BY follow the same syntax. Example: export only the last 10,000 rows of ProcessValues where the Quality column is not Bad:

SELECT TOP 10000 * FROM ProcessValues WHERE Quality <> 0 ORDER BY TimeStamp DESC

Reserved characters in column names (space, dot, dash) must be escaped with square brackets:

SELECT [Shift ID], [Batch Number] FROM BatchRecords

Date literals use the locale-dependent format. With German locale the format 'dd.mm.yyyy hh:nn:ss' is required; with US locale 'mm/dd/yyyy'. Use the runtime locale of the WinCC server, not the engineering station.

11. Service Account and File Permissions

The Global Action runs under the Windows account that started the WinCC Runtime. On a default installation this is the local CCAdmin account or the CCServiceUser defined during setup. To allow the export to write to a network share:

  1. Create or identify the service account in Active Directory.
  2. Grant the account Modify permission on the destination share and on the NTFS folder.
  3. In the WinCC service entry (services.msc → »SIMATIC WinCC Runtime« → »Log On«), set the Log On account to the service user and enter the password.
  4. Restart the WinCC Runtime service. Calendar Scheduler actions are part of the same runtime and inherit the account.
  5. Verify with a one-shot test: run the Global Action once and confirm the file appears in the share with the expected ACLs.
Security: never store the service account password in clear text inside a VBS file. Use the Windows Credential Manager via CredRead / CredWrite Win32 calls, or rely on the service account's already-authenticated session for the network share.

12. Verification Procedure

  1. In WinCC Explorer, confirm the Global Action or Calendar Scheduler action is shown with a green status icon (active).
  2. Temporarily set the monthly trigger to a time 1-2 minutes in the future to confirm end-to-end execution. Revert the schedule before handing the system to operations.
  3. Watch the destination folder for the new file. The filename should match the pattern and the file should be non-empty.
  4. Open the CSV in a text editor. Confirm the header row contains the archive column names and at least one data row follows.
  5. Inspect WinCC_Sys_<server>.log for the trigger time. Calendar Scheduler actions additionally log to CalendarScheduler.log.
  6. Verify file ACLs in Windows Explorer: right-click »Properties« → »Security« → confirm the service account or expected group has Read access.
  7. Repeat the run twice in the same month to confirm the overwrite or timestamp strategy works as designed.

13. Troubleshooting Matrix

Symptom Likely Cause Remedy
VBS action trigger icon empty VBS editor has no monthly trigger in V7.5 Switch to C action or install Calendar Scheduler V7.5 SP2
Script works on mouse click, fails on schedule Picture objects not loaded in Global Action Remove HMIRuntime.Screens / ScreenItems; use OLE DB
"Object required" in scheduled VBS Reference to unloaded picture, OLE, or ActiveX Replace with tag-based or OLE DB access
UAExport returns OK, no file written Target file already exists; UAExport does not overwrite Delete target before call, or use timestamped filename
CSV contains only the header Filter rejected by the OLE DB provider Validate the filter with a manual query in MS Access
Calendar Scheduler action never fires Calendar Scheduler service not running Start »SIMATIC WinCC Calendar Scheduler«, set to Automatic
Permission denied writing to UNC share Service account lacks share write rights Grant Modify on share + NTFS; reload service credentials
Trigger fires at the wrong time Daylight Saving Time transition Use UTC or fix the schedule to a known local time and document it
Empty archive / no rows exported User archive closed by another process Confirm archive is loaded; check »Status« in User Archive editor
CSV separator wrong for downstream tool Locale-dependent default delimiter Implement the VBS writer with explicit sDelim parameter
Runtime error -2147217865 in GSC OLE DB provider not registered on this machine Reinstall Connectivity Pack; re-register WinCCOLEDBProvider.dll
Script hangs in Publish dialog Forum-specific artifact, do not reproduce Remove any literal pattern that the editor may interpret; use a code editor and paste plain text

14. Performance and Sizing Notes

  • The adUseClient cursor (CursorLocation = 3) downloads the entire result set into the client. For an archive with millions of rows, use server-side cursors (CursorLocation = 2) and stream with rs.GetRows in chunks of 5,000 to bound memory.
  • Avoid running the export while the archive is being written to. The default User Archive cycle is 500 ms; scheduling the export for the first five seconds of the month avoids the race for most installations, but for high-frequency archives, add a Sleep or use the archive's »Close for export« API if exposed in your WinCC version.
  • For multiple archives, run them sequentially inside a single Global Action rather than scheduling one action per archive. Sequential execution avoids parallel OLE DB connections and simplifies the log trail.

15. Alternative: Windows Task Scheduler

If the VBS/Calendar Scheduler path is blocked by licensing or by operations policy, the export can be driven from schtasks on the WinCC server. A wrapper batch file calls cscript against a VBS file that opens the OLE DB connection and writes the CSV. The wrapper must be invoked under the same service account as the WinCC runtime so that WinCCOLEDBProvider.1 is registered. This path is not officially supported by Siemens for the user archive export use case but is documented as a fallback in the Connectivity Pack manual.

16. Field-Commissioning Checklist

  • Service account granted Modify on the destination share and NTFS folder.
  • Connectivity Pack installed on every machine that opens the OLE DB provider.
  • Calendar Scheduler service set to Automatic and started.
  • Global Action or Calendar action status = active (green).
  • One-shot test scheduled 1-2 minutes ahead, executed, and file confirmed.
  • Trigger reverted to first-of-month at 00:00:05 (or per operations spec).
  • Diagnostic logging enabled for both GSC and Calendar Scheduler logs.
  • Network share ACLs reviewed for the retention period (e.g. 24 months).

17. FAQ

Why does my VBS Global Action not show a Monthly trigger?

The VBS action editor in WinCC 7.5 only exposes cyclic and hotkey triggers. For monthly scheduling, use a C Global Action (built-in Monthly trigger) or install the WinCC/Calendar Scheduler V7.5 SP2 option, which supports arbitrary calendar-based scheduling for VBS.

Why does my export script work on a button click but fail as a scheduled action?

Global Actions run in the background without a loaded picture, so any reference to screen items, OLE controls, or ActiveX objects (including the UserArchiveControl) returns null and raises a script error. Switch to OLE DB access via the Connectivity Pack, which does not depend on picture objects.

UAExport completes but the target file is not overwritten. How do I fix that?

The CRT3884_UAExport sample does not overwrite existing files and returns without an error. Delete the destination before the call, or build a timestamped filename like ProcessValues_YYYYMM.csv so each monthly run produces a unique artifact.

Can I export multiple user archives in a single monthly job?

Yes. Loop through the archive names in your VBS or C routine, calling UAExport (or the OLE DB equivalent) for each one. Use distinct output paths and append the archive name to each filename to keep the outputs separate and to simplify downstream parsing.

Do I need WinCC/Connectivity Pack on the server only, or on clients too?

Install the Connectivity Pack on every machine that opens the OLE DB provider (WinCCOLEDBProvider.1). If a client triggers the export, both the server and the client need the Connectivity Pack installed and the OLE DB provider registered.

Back to blog