IMDTouchKnowledge BaseShop main store

Troubleshooting

Why a WinCC Runtime VBScript Runs but Does Not Copy a CSV

HMI and touchscreens Published 5 min read By IMDTouch engineering team

Short answer

A WinCC button script that shows no error can still copy nothing for two independent reasons: the pasted FileSystemObject example declares the source path twice and never declares the destination, and Runtime keeps an open data log locked so CopyFile cannot read it. Declare both path variables and stop and close the logs before copying.

On this page
  1. Why does the pasted FileSystemObject example not copy anything?
  2. What does the third argument of CopyFile actually do?
  3. Why does Runtime lock the CSV and stop the copy?
  4. How do I separate a script fault from a path or lock fault?
  5. What does a working test look like with real numbers?
  6. What is the final decision for each case?
  7. Questions asked

A button script in WinCC Runtime can execute to the end, raise no error, and still leave no copied file. On a Windows-based runtime such as Runtime Advanced on an IPC, two independent faults explain almost every case: the widely circulated FileSystemObject example declares the wrong variables, and Runtime keeps an open data log locked so no copy can read it. Fix the script first, then stop and close the logs, then retest; the same button-works-but-nothing-happens pattern also appears when a panel button launches nothing, which is why the checks below separate script faults from environment faults.

Why does the pasted FileSystemObject example not copy anything? #

The example circulating for TIA Portal scripting contains a declaration error: it declares MyPathWithFile1 twice and never declares MyPathWithFile2, yet assigns and uses MyPathWithFile2 later. With Option Explicit behavior or strict checking, the destination assignment is invalid; even where it is tolerated, you cannot trust which path the copy actually used. This applies on a Windows runtime where Scripting.FileSystemObject is created with CreateObject; the panel-side FileCtl.FileSystem object belongs to WinCE panels and is the wrong tool on a PC. The same class of fault appears in other script problems, such as an SQL read script that returns nothing, where the code runs but the data path is broken.

The corrected script declares both paths and enables overwrite:

Dim MyObjectFile
Dim MyPathWithFile1, MyPathWithFile2
Set MyObjectFile = CreateObject("Scripting.FileSystemObject")
MyPathWithFile1 = "\\IPC-Siemens\MyFolder\MyFile.csv"
MyPathWithFile2 = "\\IPC-Siemens\MyFileCopied.csv"
MyObjectFile.CopyFile MyPathWithFile1, MyPathWithFile2, True
Set MyObjectFile = Nothing

Both paths above are illustrative: substitute a verified source path and destination path for your IPC, because a script that points at a nonexistent share also runs without copying.

What does the third argument of CopyFile actually do? #

The third argument of CopyFile is the overwrite flag, and passing True is the difference between a copy and an error. Per the method's documented behavior: if the destination is an existing file, an error occurs when overwrite is False; with True, the source is copied over the existing file. In a button script without error handling, that error can surface as nothing visible on screen, which is exactly the silent-failure symptom. Decide it this way: pass True for a rolling export that replaces yesterday's copy, and pass False only when you have an On Error handler that catches and reports the collision.

Why does Runtime lock the CSV and stop the copy? #

Runtime holds an open data log file locked, so the file cannot be copied while logging is active. If your source CSV is a Runtime data log, the copy fails not because the script is wrong but because the file is open. The documented procedure is to stop and close all affected logs first, run the copy, then restart logging. For cyclic-selective logging you can configure a start/stop tag: logging stops as soon as the start condition is no longer in effect, so your script (or the operator) writes the stop value, waits for the file to be released, copies, and writes the start value again. Copying while the log is still open is not a valid test of the script.

How do I separate a script fault from a path or lock fault? #

Work through these checks in order, changing only one thing per run:

  • Declare both path variables, as in the corrected script above, and pass True as the overwrite argument.
  • Confirm the source file exists at the exact path typed in the script, including the share name and folder.
  • Confirm the destination folder is reachable and that the account running Runtime has write access there.
  • If the CSV is a Runtime log, stop and close every affected log before pressing the button.
  • Add a debug write at the end of the script and read the WinCC system alarms after each button press; a script that ends silently has not proven anything.
  • Retest on the bench with a small test CSV that is not a live log; if the copy works there, the remaining fault is the log lock.

What does a working test look like with real numbers? #

A worked example: suppose your log is configured with a 1-second logging cycle, the minimum cycle for WinCC Advanced, and each record is about 80 bytes. Over one 8-hour shift that is 8 × 3600 = 28,800 records, about 28,800 × 80 = 2,304,000 bytes, roughly 2.3 MB. On a local disk that copy takes well under a second; over a network share at a conservative 10 MB/s it takes about 0.23 seconds. Decision rule from those numbers: if the destination file appears within a couple of seconds after the logs are stopped, the script and path are fine; if the source is about that size and nothing appears even after the logs are closed, the fault is in the path or access rights, not the lock.

What is the final decision for each case? #

Commit to the fix that matches your symptom:

  • Script came from the circulated example: replace it with the corrected version above, both paths declared, overwrite True.
  • Copy works for an ordinary file but not the CSV log: the log is locked; stop and close the logs, copy, restart.
  • Nothing copies even from a small test file: the path or permissions are wrong; verify the source path character by character and the Runtime account's write access to the destination.
  • Button does nothing at all, not even a debug entry: the script is not firing; check the button's event assignment before touching the copy code.

Questions asked

Why does my WinCC VBScript run without an error but the CSV is still not copied?

Two causes cover most cases: the data log is still open in Runtime and locked against reading, or the script's path variables are wrong. The commonly pasted example declares MyPathWithFile1 twice and never declares MyPathWithFile2, so the destination assignment fails. Fix both, then retest.

How do I overwrite an existing CSV with FileSystemObject CopyFile?

Pass True as the third argument of CopyFile. With False, the method raises an error when the destination file already exists; with True it copies the source over the existing file. In a button script, an unhandled error of this kind can look like a silent no-op.

Can I use the WinCE panel FileCtl.FileSystem object on a PC Runtime?

No. FileCtl.FileSystem belongs to the WinCE panel scripting environment. On a Windows-based runtime such as Runtime Advanced on an IPC, use Scripting.FileSystemObject created with CreateObject, and confirm the method works on your exact runtime version by a bench test.

How do I stop a WinCC data log from my script before copying?

Configure a start/stop tag for the log in the logging configuration and have the script write the stop value to that tag first. Logging stops when the start condition is no longer in effect and the file is released, after which the copy can proceed and the tag can restart logging.

Keep reading

  • Explainer

    Why WinCC Unified scripts export tag data as CSV, not Excel

    A WinCC Unified runtime script cannot write an .xlsx file: its JavaScript environment exposes tags, screen items, alarms and system functions, with no file-system or zip library, and an Excel workbook is a zipped XML package. Log the tags, select a start and end time on a screen, and export that range as CSV from the trend control's export or an external log reader, converting UTC to local time in one place.

    HMI and touchscreens

  • Troubleshooting

    Why WinCC Logging for Runtime Advanced asks for a license

    The message means the runtime computer holds no valid option key for historical logging; the base WinCC Runtime Advanced license never covers it. Order WinCC Logging for Runtime Advanced (6AV2107-0GA00-0BB0), one per operator station, and install or transfer the key with Automation License Manager; keys from generators or copied folders do not clear it.

    HMI and touchscreens

  • Troubleshooting

    Why MTP1500 CSV log export needs a script in TIA V20

    On an MTP1500 engineered in TIA Portal V20 there is no ExportTagLog system function and no Comfort-style CloseAllLogs/ArchiveLogFile/OpenAllLogs sequence, because Unified logs are SQLite segments, not TXT or CSV files. The documented route is the supplied snippet under Snippets > HMI Runtime > Tag Logging > Export Tag Log as CSV, sequenced with status tags so logging stays open and no samples are lost.

    HMI and touchscreens

Why a PanelView 5310 Says Not a Valid Device for an MER File