Problem: Reading Excel Data from a Siemens MP377 HMI
A VBScript running on a Siemens MP 377 Comfort Panel cannot instantiate the Excel COM object. The classic Windows desktop pattern CreateObject("Excel.Application") works on a WinCC flexible Engineering Station but fails on the panel runtime because the panel does not ship with the Microsoft Office automation layer. The robust workaround is to convert the spreadsheet to a CSV (comma-separated values) text file and read that text file from the panel using Scripting.FileSystemObject exposed by the WinCC flexible Runtime.
This article covers the CSV-based method end to end: the panel operating-system limits that block Excel COM, the supported VBScript object model on the MP 377, the panel file-system paths, a working script that opens a CSV and returns the value of any cell into an HMI tag, plus a verification and troubleshooting matrix.
Why CreateObject("Excel.Application") Fails on the MP 377
Siemens MP 377 panels ship with an embedded Windows operating system that does not include Excel, Word, or any Office automation type library. The runtime images are stripped to the small set of components needed to host the WinCC flexible Runtime, the HMI screen engine, and the Web Client. Excel.Application is registered through excel.exe and the Office type libraries in the Windows registry; both are absent.
| Panel | Operating System | Excel COM Available? | VBScript Available? | FileSystemObject Available? |
|---|---|---|---|---|
| MP 377 12" Touch (6AV6644-0AA01-2AX0) | Windows CE 5.0 / 6.0 | No | Yes (WinCC flexible) | Yes |
| MP 377 15" Touch (6AV6644-0AB01-2AX0) | Windows CE 6.0 | No | Yes | Yes |
| MP 377 19" Touch (6AV6644-0AC01-2AX0) | Windows CE 6.0 | No | Yes | Yes |
| MP 377 Key variants | Windows CE 5.0 / 6.0 | No | Yes | Yes |
| Engineering Station (PG/PC) | Windows 10 / 11 | Yes (if Office installed) | Yes | Yes |
When the runtime attempts Set oExcel = CreateObject("Excel.Application") on the panel, the COM call returns error 429 ("ActiveX component can't create object") because the CLSID for Excel.Application is not registered. A second, more subtle failure is that the script may simply hang while waiting for the COM subsystem to time out; in that case the WinCC flexible Runtime scheduler marks the script as blocked and the entire HMI may stop responding until the script is killed.
Supported VBScript Object Model on the Panel
WinCC flexible Runtime exposes a limited VBScript host. The available automation objects are documented in the WinCC flexible help under VBScript Reference and the panel manuals in the Siemens Industry Online Support. The most useful set is:
| Object | Use on the Panel |
|---|---|
HMIRuntime |
Read/write HMI tags, schedule timers, log events |
Scripting.FileSystemObject |
Open, read, write, delete files and folders on the panel storage |
WScript.Shell |
Limited; some methods restricted by the security policy |
Scripting.Dictionary |
In-memory key/value stores |
Err object |
Structured error handling in scripts |
External COM objects such as Excel.Application, ADODB.Connection, or MSXML2.DOMDocument are not guaranteed. Treat any feature not in the table above as unsupported and design around it.
Prerequisites
- WinCC flexible 2008 SP3 or TIA Portal V13 SP1+ with the WinCC Comfort/Advanced option installed on the engineering station.
- A Siemens MP 377 panel with firmware matching the configured runtime version (for TIA Portal V16 use the matching panel image and update via ProSave).
- An external storage card (SD or MMC, at least 1 GB, formatted FAT32) inserted in the panel, or a network share reachable from the panel via SMB/CIFS.
- The Excel source file converted to a CSV file (UTF-8, comma-separated, header row optional) on the engineering station.
- A VBScript function scheduled in WinCC flexible, called either from a button event or from a Change value trigger on an HMI tag.
Step-by-Step: Convert the Excel File to CSV
The MP 377 cannot parse the binary XLS/XLSX container. Convert on the engineering station before deploying the file to the panel. The CSV must use a delimiter that does not appear inside the data; comma is the most common. If the cell values contain commas, either change the delimiter (semicolon is a frequent choice in European locales) or quote the values.
- Open
file.xlsin Microsoft Excel. - Choose File → Save As and select CSV (Comma delimited) (*.csv) as the file type.
- Confirm the warning about features that are not compatible with CSV. Click OK.
- Repeat for every worksheet that must be available on the panel, saving each sheet as a separate CSV (e.g.
recipe.csv,parameters.csv). - Copy the resulting CSV file(s) to the panel storage card, for example to
\Storage Card2\Recipes\.
If the CSV is regenerated frequently by an external system (SCADA server, MES, or database export), expose a network share at \\<server>\share\ reachable from the panel and read directly from that share.
Step-by-Step: Project Setup in TIA Portal / WinCC flexible
- Open the TIA Portal project that targets the MP 377 (device family: Comfort Panel → MP 377).
- Create a new HMI tag, e.g.
RecipeDataStringof type WString with a length of 254 characters. This is the destination of the cell value read from the CSV. - Open HMI tags → Recipes if a recipe view is required, or use the simple tag for the example.
- Add a new VBScript function: Scripts → VBScripts → Add new. Name it
ReadCsvCell. - Define the function parameters and paste the body shown in the next section.
- Trigger the function from a button Press event, or schedule it on a 1-second timer using the Scheduler wizard if the CSV is updated continuously.
- Download the project to the panel with Online → Extended download to device and select Overwrite all for the runtime files.
VBScript: Read a Single Cell from a CSV File
The function below opens a CSV on the panel, locates a cell by (row, column) index, and writes the string value into an HMI tag. The row and column indexes are 1-based, matching Excel's convention.
' WinCC flexible / TIA Portal VBScript - read a CSV cell on a Comfort Panel
' Target panel: MP 377 (Windows CE)
' Tested runtime: WinCC Comfort/Advanced V16
Const ForReading = 1
Const FilePath = "\Storage Card2\Recipes\recipe.csv"
Sub ReadCsvCell(ByVal iRow As Integer, ByVal iCol As Integer)
Dim oFSO, oFile, sLine, sValue
Dim aCols(), i
On Error Resume Next
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Err.Number <> 0 Then
HMIRuntime.Trace "FSO create failed: " & Err.Description
Exit Sub
End If
Err.Clear
If Not oFSO.FileExists(FilePath) Then
HMIRuntime.Trace "CSV not found: " & FilePath
Exit Sub
End If
Set oFile = oFSO.OpenTextFile(FilePath, ForReading, False, -1) ' -1 = Unicode
If Err.Number <> 0 Then
HMIRuntime.Trace "OpenTextFile failed: " & Err.Description
Exit Sub
End If
Err.Clear
i = 0
Do While Not oFile.AtEndOfStream
i = i + 1
sLine = oFile.ReadLine
If i = iRow Then
' Split on a semicolon for European locale CSVs.
' Change the delimiter to "," if the file is US-style.
aCols = Split(sLine, ";")
If iCol <= UBound(aCols) + 1 Then
sValue = aCols(iCol - 1)
Else
sValue = ""
End If
Exit Do
End If
Loop
oFile.Close
' Trim CR/LF and any wrapping double quotes that Excel added.
sValue = Replace(sValue, Chr(34), "")
sValue = Trim(sValue)
HMIRuntime.Tags("RecipeDataString").Write sValue
HMIRuntime.Trace "ReadCsvCell row=" & iRow & " col=" & iCol & " value=" & sValue
On Error Goto 0
End Sub
Key points for the script to work on the MP 377:
- Use backslashes in the path; the panel uses a Windows-style path but the drive letters are mapped to Storage Card2, Flash, etc.
- Pass the unicode flag (-1) to
OpenTextFileso that accented characters in the CSV survive the round trip. - Use
HMIRuntime.Tracefor diagnostics; the messages are visible in the WinCC trace log and in the ProSave diagnostic view. - Always call
oFile.Close; file handles left open consume the limited panel memory pool.
VBScript: Read the Full CSV into a 2-D Array
When the application needs to look up multiple cells per cycle, the efficient pattern is to read the file once into a 2-D VBScript array. The example below uses an in-memory dictionary for fast row lookup by a key column.
Dim g_aData() ' 2-D array
Dim g_iRows
Dim g_iCols
Dim g_oIndex ' Scripting.Dictionary <key, row index>
Sub LoadCsvToMemory(ByVal sPath As String, ByVal sDelim As String, ByVal iKeyCol As Integer)
Dim oFSO, oFile, sLine, aCols, i, j
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(sPath, 1, False, -1)
g_oIndex.RemoveAll
g_iRows = 0
g_iCols = 0
Do While Not oFile.AtEndOfStream
sLine = oFile.ReadLine
aCols = Split(sLine, sDelim)
g_iRows = g_iRows + 1
ReDim Preserve g_aData(g_iRows, UBound(aCols) + 1)
For j = 0 To UBound(aCols)
g_aData(g_iRows, j + 1) = Replace(aCols(j), Chr(34), "")
Next
g_iCols = UBound(aCols) + 1
If iKeyCol > 0 And iKeyCol <= g_iCols Then
g_oIndex(CStr(g_aData(g_iRows, iKeyCol))) = g_iRows
End If
Loop
oFile.Close
End Sub
Function GetCellByKey(ByVal sKey As String, ByVal iCol As Integer) As String
If g_oIndex.Exists(sKey) Then
GetCellByKey = CStr(g_aData(g_oIndex(sKey), iCol))
Else
GetCellByKey = ""
End If
End Function
Writing the Cell Value to an HMI Tag
HMI tags are accessed through the HMIRuntime object. The Write method triggers a tag update, which the HMI screens, the scheduler, and any connected S7 controller can see. For recipe data, a WString tag of length 254 is sufficient for most use cases; for numeric values, use the conversion functions in VBScript (CDbl, CInt) and then write to a Real or Integer tag.
' Example: read numeric cell and write to a real tag
Dim sVal, dVal
sVal = GetCellByKey("MOTOR_SPEED", 3)
dVal = CDbl(sVal)
If Err.Number = 0 Then
HMIRuntime.Tags("SetpointSpeed").Write dVal
Else
HMIRuntime.Trace "Conversion error: " & sVal
Err.Clear
End If
Panel File System Paths and Storage Strategy
The MP 377 exposes a small set of fixed path roots. Do not hardcode drive letters; refer to the logical names that survive firmware updates.
| Logical Path | Physical Media | Use Case |
|---|---|---|
\Storage Card2\ |
External SD card | Recipes, CSV imports/exports, user data |
\Storage Card MMC\ |
Internal flash on some variants | Permanent project files |
\Flash\ |
Internal flash | Firmware, project image, system files |
\USB Storage\ |
External USB stick (if supported) | Bulk transfer, service tool |
\\<server>\share\ |
Network share | Live data from MES/ERP |
CSV files belong on the external SD card. The card is removable, can be cloned, and survives a project download. The internal flash has a finite write-cycle budget and is not recommended for files that change often.
Handling Encodings and Delimiters
Excel on a German Windows defaults to a semicolon delimiter; on a US Windows to a comma. The MP 377 WinCC flexible Runtime reads the file as Unicode or ASCII depending on the flag passed to OpenTextFile. Use the following rules:
- Save the CSV as CSV UTF-8 (Comma delimited) (*.csv) from Excel. The BOM at the start of the file lets the panel detect UTF-8.
- Open with
OpenTextFile(path, 1, False, -1)for Unicode, or withOpenTextFile(path, 1, False, 0)for ASCII. - Strip the BOM bytes (0xEF 0xBB 0xBF) from the first cell if they survive the read.
- For CSVs that contain quoted fields with embedded delimiters, write a small state machine that toggles a flag on every
"character. The simpleSplitcall above will mis-tokenize such lines.
Security Policy and Script Restrictions
WinCC flexible Runtime enforces a script permission set. The default policy blocks scripts from accessing network resources and from writing to the system flash. If a script needs to read a network share, the operator must enable the Allow network access checkbox in the runtime settings. The path to the setting is Device settings → Runtime settings → Services → VBScript.
| Setting | Default | Required For |
|---|---|---|
| VBScript enabled | On | Any VBScript execution |
| Allow file access | On | Local SD/flash read/write |
| Allow network access | Off | Reading from a network share |
| Allow ActiveX | Off | External COM objects (not used here) |
Performance: How Often Can the Panel Read a CSV?
The MP 377 has a 533 MHz ARM11-class CPU and 128 MB of working memory. Reading a 1 MB CSV with FileSystemObject takes about 80 to 150 ms on a typical SD card. Splitting and storing in a dictionary adds another 20 to 40 ms. Plan the trigger as follows:
- Trigger by event: best for user-initiated actions (button press, value change).
- Trigger by 1 s scheduler: safe for files up to 200 KB.
- Trigger by 100 ms scheduler: only for files under 20 KB, and only if the file is loaded into memory once and read from RAM thereafter.
For continuous high-frequency updates from a server, prefer the WinCC flexible Data Transfer or OPC UA server to push values into tags directly, bypassing the file system entirely.
Troubleshooting Matrix
| Symptom | Probable Cause | Diagnostic Step | Fix |
|---|---|---|---|
| Script does nothing; no trace message | VBScript disabled in runtime settings | Check Runtime settings → Services → VBScript | Enable VBScript and reload the runtime |
| Error 429 "ActiveX component can't create object" | Attempted CreateObject("Excel.Application") on the panel |
Search the script for any "Excel" string | Replace with CSV + FileSystemObject |
| Trace: "CSV not found" | Wrong path or SD card not inserted | Check File → Explorer on the panel | Use \Storage Card2\ and ensure card is present |
| Value contains garbled characters | Encoding mismatch (UTF-8 read as ASCII) | Check first bytes of file for 0xEF 0xBB 0xBF | Open with unicode flag and strip BOM |
| Value is empty for valid cell | Delimiter mismatch (comma vs semicolon) | Inspect the first CSV line on a PC | Match the Split delimiter to the file |
| Panel hangs after script runs | File handle not closed | Check trace for repeated "Open" | Always call oFile.Close in every path |
| Tag does not update on screen | Tag is in the wrong connection or is internal | Check the tag's connection and update cycle | Set the tag's acquisition cycle to 1 s |
| Network share path fails | Network access disabled in runtime security | Check Allow network access setting | Enable, supply credentials in User administration |
Verification Procedure
- Create a test CSV
verify.csvwith three rows:A1;B1;C1/A2;B2;C2/A3;B3;C3and place it on the SD card. - Add an output field on the MP 377 screen bound to the
RecipeDataStringtag. - Press the test button. Confirm the field shows
B2after the script runs. - Open the WinCC flexible diagnostic view (Start → Programs → ProSave → Panel diagnostics) and check the trace log for the line
ReadCsvCell row=2 col=2 value=B2. - Modify the CSV on the SD card from a PC, re-insert, and press the button again. Confirm the new value appears on the screen.
- Reboot the panel. Confirm the value is reloaded on the first trigger after boot (the script runs on every event; no caching of the file is required).
Alternative: Reading from a Network Share
If the panel is on the plant network, the CSV can live on a Windows share. The VBScript does not change; only the path becomes \\PLANTSRV\Recipes\recipe.csv. Required runtime settings:
- Enable Allow network access on the panel.
- Configure the panel user in User administration → Users with a Windows account that has read access to the share.
- On the server, enable SMB1 or SMB2 file sharing (the MP 377 supports up to SMB2 depending on the firmware).
- Test the path with a
oFSO.FileExistscall before opening.
For an OPC UA based data feed, use the Siemens Industry Online Support documentation for the WinCC Comfort OPC UA server; the CSV is replaced by an OPC UA item read.
What About TIA Portal V17 / V18 Comfort Panels?
The MP 377 is a legacy Comfort Panel. Current TIA Portal versions (V17, V18) still support it as a target, but new deployments typically use the Unified Comfort Panel (MTP1500, MTP1900, MTP2200) running WinCC Unified. On Unified, the VBScript host is replaced by JavaScript and FileSystemObject is not available. The equivalent is the FileSystem API in the Unified JavaScript runtime. The CSV approach is the same; the API calls differ.
Field-Proven Caveats
- Always size the WString tag longer than the longest expected cell. Excel can hold 32,767 characters; the panel tag is usually limited to 254 or 1024. Truncate in the script with
Left(sValue, 254). - When the CSV is updated by another system, use a "ready" flag file. The script checks for the presence of
recipe.csv.readybefore readingrecipe.csv; the writer creates the data file first, then the flag file, then deletes the flag file on the next cycle. This prevents reading a half-written file. - For 64-bit Office on the engineering station, the VBScript still runs as 32-bit; no special handling is required, but watch for ODBC data source names that were created under 64-bit Office and are not visible to the 32-bit script host.
- Do not use
oExcel.Cells(row, column)at all on the panel. The whole concept of a "cell" must be replaced by row/column indexing into a text file. - If the panel runs out of working memory, the WinCC flexible Runtime silently kills the oldest script. Trace the memory headroom with
HMIRuntime.Trace "Mem free: " & oFSO.Drives.Countat the end of long scripts.
FAQ
Why does my VBScript work on the engineering PC but not on the MP 377 panel?
On the engineering PC, Excel.Application is registered by the Office install. On the MP 377, the embedded Windows CE image does not include the Office automation layer, so CreateObject("Excel.Application") fails with error 429. Convert the data to CSV and use Scripting.FileSystemObject on the panel.
What file path should I use on the MP 377 to read a CSV?
Use the logical name \Storage Card2\<folder>\<file>.csv for an external SD card, or \Flash\<folder>\<file>.csv for internal flash. Do not hardcode a Windows drive letter; the logical names survive firmware updates.
How do I handle a CSV that uses semicolons instead of commas?
Excel on a German or French Windows defaults to semicolons. Pass the correct delimiter to the Split call: Split(sLine, ";"). For mixed or quoted fields, write a small state machine that tracks whether the parser is inside a quoted string.
Can I use the same script on a Unified Comfort Panel?
No. The Unified runtime replaces VBScript with JavaScript and removes FileSystemObject. Use the Unified FileSystem API in a JavaScript function with the equivalent readFile and Split calls. The CSV approach on the file system is the same.
How do I read a numeric cell value into a numeric HMI tag?
Use CDbl(sValue) or CInt(sValue) on the string returned by the split, wrap the conversion in On Error Resume Next plus a check on Err.Number, and call HMIRuntime.Tags("MyTag").Write dVal with the numeric value. Make sure the target tag is type Real or Integer, not WString.
Where can I find official documentation for VBScript on the panel?
The WinCC flexible VBScript reference and panel manuals are in the Siemens Industry Online Support under WinCC flexible 2008 and TIA Portal WinCC Comfort/Advanced. The Microsoft Excel read tutorial documents the modern desktop equivalent.