0% found this document useful (0 votes)
147 views

WinCC TIA VB Script Data Logging To Excel (CSV)

This VBScript subroutine exports data to a CSV file. It first checks if the export folder and file exist, creating them if not. It then opens the file, writes a header row, and writes the data values separated by semicolons. Finally, it closes and releases the file object.

Uploaded by

ben chko
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

WinCC TIA VB Script Data Logging To Excel (CSV)

This VBScript subroutine exports data to a CSV file. It first checks if the export folder and file exist, creating them if not. It then opens the file, writes a header row, and writes the data values separated by semicolons. Finally, it closes and releases the file object.

Uploaded by

ben chko
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Sub tmpExport_1()

Dim FolderPath, ObjectPath, Filename, File, FileExist, Columns, Row

FolderPath = "C:\_DOC\"
Filename = "test_log.csv"

'Object creation
Set ObjectPath = CreateObject("Scripting.FilesystemObject")

'Check if folder exists


If Not ObjectPath.FolderExists(FolderPath) Then
ObjectPath.CreateFolder FolderPath
End If

' Check if file exists


Set File = CreateObject("Scripting.FilesystemObject")
FileExist = File.FileExists(FolderPath & "\" & Filename)
If FileExist = False Then
File.CreateTextFile(FolderPath & "\" & Filename)
Set Columns = File.OpenTextFile(FolderPath & "\" & Filename, 8)
Columns.WriteLine("Data1 ; Data2 ; Data3")
Columns.Close
Set File = Nothing
End If

'Write data to file


Set File = CreateObject("Scripting.FilesystemObject")
Set Row = File.OpenTextFile(FolderPath & "\" & Filename, 8)
Row.WriteLine(SmartTags("zLogReal1") & ";" & SmartTags("zLogReal2") & ";" &
SmartTags("zLogReal3") & ";")
Row.Close

'Free memory
Set File = Nothing ‘Here we are releasing the file.

End Sub

You might also like