Wincc to Excel VBS scripting.

Join Date
Nov 2014
Location
ulaanbaatar
Posts
10
Hello everyone. I'm trying to export data to excel from Wincc.
My code is global action that executed every second that create excel filer per minute and write on excel every second.

But i cant save changes to excel. anyone help hellp?


Option Explicit
Function action

Dim Dat
Dim Sec
Dim Min
Dim Exce
Dim SheetNam
Dim i
Dim fso
Dim WB
Dat = FormatDateTime(Now,vbShortDate)
Sec = Second(Now)
Min = Minute(Now)
SheetNam = "Report"

Set Exce = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")


If(fso.FileExists("C:\Users\User\Desktop\excel\"&Min&".xlsx")) Then

Set WB = Exce.Workbooks.Open("C:\Users\User\Desktop\excel\"&Min&".xlsx")
Exce.Application.DisplayAlerts = False
Exce.Application.Visible = False

Exce.Cells(1, 1).Value = "Editing1"
Exce.Cells(1, 2).Value = "editing2"
Exce.Cells(2, 1).Value = "up3"
Exce.Cells(2, 2).Value = "danching machine"

Select Case Sec

Case 0
Exce.Cells(3, 1).Value = "0 Second"
Exce.Cells(4, 2).Value = HMIRuntime.Tags("Value_excel")

Case 1
Exce.Cells(3, 2).Value = "1 Second"
Exce.Cells(4, 2).Value = HMIRuntime.Tags("Value_excel")
Case 2
Exce.Cells(3, 3).Value = "2 Second"
Exce.Cells(4, 2).Value = HMIRuntime.Tags("Value_excel")
Case 3
Exce.Cells(3, 4).Value = "3 Second"
Exce.Cells(4, 4).Value = HMIRuntime.Tags("Value_excel")
Case 4
Exce.Cells(3, 5).Value = "4 Second"
Exce.Cells(4, 5).Value = HMIRuntime.Tags("Value_excel")

End Select
Exce.ActiveWorkbook.Save "C:\Users\User\Desktop\excel\"&Min&".xlsx"
Exce.ActiveWorkbook.Close

Exce.ActiveWorkbook.Sheet(1) = Nothing
Exce.ActiveWorkbook.Open = Nothing

Exce.Quit
Else
Exce.Application.Visible = False
Exce.Workbooks.Add
Exce.Worksheets(1).Name = SheetNam
Exce.Worksheets(SheetNam).range("A1") = "Create"
Exce.Worksheets(1).SaveAs("C:\Users\User\Desktop\excel\"&Min&".xlsx")
Exce.ActiveWorkbook.Close
Exce.Quit

End If


End Functi
 
Last edited:

Similar Topics

hello guys... i m looking for example how to send excel recepi to wincc flexiable (HMI) and when click particular formula it will start using the...
Replies
1
Views
1,848
Hi guys, I'm currently busy with a Wincc project which requires me to dump field data and physical inputs entered by an operator on a Wincc scada...
Replies
5
Views
2,065
Hello all, I am using Win CC v7.2, I would like to do a couple of data and information transfers to either ecel or csv ortext files onto the pc...
Replies
0
Views
3,211
Hello, I want to store data in WinCC into Excel, Like daily hour wise report or monthly report. I have never attempted this stuff can anybody...
Replies
25
Views
14,694
Hello, I want to make a button in WinCC (Runtime) that will send data whatis excist in a datablock of Siemens S7-300 to Excel. Example: DB1 with...
Replies
0
Views
1,635
Back
Top Bottom