tsenguun odgerel
Member
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?
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: