plc.myforum.ro Forum Index plc.myforum.ro
PLCs users www.plc.myforum.ro!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

wincc to excel sheet

 
Post new topic   Reply to topic    plc.myforum.ro Forum Index -> Simatic Automation Systems
View previous topic :: View next topic  
Author Message
leemoooo
Junior
Junior


Joined: 23 Feb 2017
Posts: 1

PostPosted: 23/02/2017 15:01    Post subject: wincc to excel sheet Reply with quote

Pls expert ,
urgent i have some parameters in my PCS7 ( pressure, flow) , and i need to export these data to excel sheet daily morning>
Pls i need a help
waiting ur replay. :whistle:
Back to top
View user's profile Send private message
jingo
Member junior
Member junior


Joined: 19 Oct 2015
Posts: 51
Location: New Mexico

PostPosted: 23/02/2017 15:37    Post subject: Re: wincc to excel sheet Reply with quote

leemoooo wrote:
Pls expert ,
urgent i have some parameters in my PCS7 ( pressure, flow) , and i need to export these data to excel sheet daily morning>
Pls i need a help
waiting ur replay. :whistle:


use DataBridge for wincc
http://plc.myforum.ro/wincc-industrialdatabridge-writing-data-in-ms-office-files-vt7237.html
or
http://plc.myforum.ro/how-do-you-create-an-opc-client-with-microsoft-excel-vt7979.html
or in a scrip from wizzard
WinCC > VBS for creating Procedures and Actions > Examples of VBScript > General examples > Example: Using the MS Automation Interface

for s7 use
http://plc.myforum.ro/read-write-db-from-to-s7-from-to-excel-vt7085.html

or in a sheet example
Code:
Sub New_Wicc_excel

'VBS113


Dim objExcelApp
Dim MyDate
MyDate = Date


Dim MyVar
MyVar = Now


Dim i
i = Day (Date) ' Retun value of current date day value exp = todays date no (any 1 to 31)


Dim Hsm_oxygen,Hsm_Nitrogen,Hsm_Argon
Set Hsm_oxygen = HMIRuntime.Tags("HSM_Oxygen")
Set Hsm_Nitrogen = HMIRuntime.Tags("HSM_Nitrogen")
Set Hsm_Argon = HMIRuntime.Tags("HSM_Argon")
Hsm_oxygen.Read
Hsm_Nitrogen.Read
Hsm_Argon.Read

Set objExcelApp = CreateObject("Excel.Application")

objExcelApp.Visible = True

objExcelApp.Workbooks.Add

objExcelApp.Workbooks.Open "c:\ExcelExample.xls"


objExcelApp.cells(i+1, 3).Value = MyDate '(row,colum)

objExcelApp.Cells(i+1, 4).Value = ScreenItems("excelvalue").OutputValue 'colum =current date ,row =3 ,value iofield 3
objExcelApp.Cells (i+1, 5).Value =Hsm_oxygen.Value
objExcelApp.Cells (i+1, 6).Value =Hsm_Nitrogen.Value
objExcelApp.Cells (i+1, 7).Value =Hsm_Argon.Value


objExcelApp.ActiveWorkbook.Save

objExcelApp.Workbooks.Close

objExcelApp.Quit

Set objExcelApp = Nothing


End Sub



WinCC/DataMonitor install as option to WinCC (check your installation program)
http://w3.siemens.com/mcms/human-machine-interface/en/visualization-software/scada/wincc-options/wincc-datamonitor/Pages/Default.aspx

Code:
Display and analysis of current process states and historical data (measured values, messages, user data) on any office PC. The data provider, a WinCC/WebNavigator or a WinCC/DataMonitor server can be installed on any WinCC single-user system, server or client.

The WinCC/DataMonitor offers Internet-capable tools, which support all conventional security mechanisms such as login/password, firewalls, encryption, etc.:

    Process Screens
    Monitoring and navigating using WinCC process screens with MS Internet Explorer as so-called "View Only Client". The mechanisms of WinCC/Web Navigator are used.

    Trends & Alarms
    Display and analysis of archived WinCC process values and alarms. Predefined webpages are linked to WinCC archive data (measured values or messages) for this purpose. The report data can be exported to a CSV file.

    Excel Workbooks
    Messages, current or archived process values are transferred to an Excel table with the help of a wizard. The Excel workbooks can be published, made available on the intranet/Internet or used as a template for automated reports (published reports).

    Published Reports
    Generation of time-driven or event-driven reports as Excel file or PDF
    and forwarding by email, if required.

    WebCenter
    Central information portal for access to WinCC data via the intranet or Internet. Any data views and WinCC process pictures can be compiled for different groups of persons. This means data can be analyzed and exported over different periods of time. It is also possible to connect or disconnect outsourced archives.


or write to a file
Code:
Dim fso, f, FName, DataSet, Header, Storage_Path
Dim ForAppending

'File open for appending
ForAppending = 8

' Define Storage path
Storage_Path = "D:\"

' Combine archivepath (input parameter) and filename -> Archiv
FName = Storage_Path & "FileName.csv"

' Fabricate table header
Header = "Time;Speed[%]"

' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Confecționate FileObject , if file do not exist it will be created if file exist, open for append
Set f = fso.OpenTextFile(FName,ForAppending,True)   

'for control
HMIRuntime.Trace("VB-Script: Write file: " & FName & vbCrLf)
   
' If file is 0 byte the file is new - insert table header
 If fso.GetFile(FName).Size = 0 Then
    f.WriteLine Header
   ' =0 => Table header must be inserted
 End If

 ' Write values of variables in archive file (Tag_x)
DataSet = CStr(Now) & ";" & HMIRuntime.Tags("xxxSpeed").Read
      
f.WriteLine DataSet                 'Write the DataSet in File'   
f.Close                             'Close File'   


'for control
HMIRuntime.Trace(DataSet & vbCrLf)

' Used storage will be freed
Set f  = Nothing
Set fso = Nothing


or this code for inverse purpose
VB Script to Read values from MS Excel and Write tag values in WinCC
Code:


Sub OnLButtonDown(Byval Item, Byval Flags, Byval x, Byval y)
Dim objExcelApp
Dim objWorkSheet
Dim objTag1,objTag2
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Visible = True
objExcelApp.Workbooks.Open "D:\Excel file.xls"
set objWorkSheet = objExcelApp.Activeworkbook.Worksheets(1)

Set objTag1= HMIRuntime.Tags("Tag1 name")
Set objTag2= HMIRuntime.Tags("Tag2 name")

objTag1.Value= objWorkSheet.Cells(2,4).Value
objTag2.Value= objWorkSheet.Cells(3,4).Value

objTag1.Write
objTag2.Write

objExcelApp.ActiveWorkbook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objTag1= Nothing
Set objTag2= Nothing

End Sub


writing data to excel with global script
Code:

Dim a
Dim objExcelApp,objExcelApp2
Dim DT
Dim DY,MNTH,YR,MNTHNM
Dim HR,MNT,SCND
Dim i,j
Dim fso, msg,fldr,ReportFolderStatus
Dim fso1, f,fName

DY=Day(Date())
MNTH=Month(Date())
YR=Year(Date())

HR=Hour(Time())
MNT=Minute(Time())
SCND=Second(Time())

MNTHNM=Month(Now)
MNTHNM=MonthName (MNTHNM,True)

DT=DY & "_" & MNTH & "_" & YR & "_" & HR & "_" & MNT & "_" & SCND

If (HMIRuntime.Tags("SHIFT_TRIGGER").Read >0) Then

Set fso = CreateObject("Scripting.FileSystemObject")

Set objExcelApp = CreateObject("Excel.Application")

objExcelApp.Visible = False

objExcelApp.Workbooks.Open "D:\BATCH_REPORT.xls"
objExcelApp.ActiveWorkbook.Save

If (fso.FolderExists("E:\REPORTS_EVEREST")) Then

If (fso.FolderExists("E:\REPORTS_EVEREST\" & MNTHNM)) Then
objExcelApp.ActiveWorkbook.Saveas "E:\REPORTS_EVEREST\" & MNTHNM & "\BATCH_REPORT_" & DT & ".XLS"
Else
Set fso1 = CreateObject("Scripting.FileSystemObject")
Set f = fso1.CreateFolder("E:\REPORTS_EVEREST\"& MNTHNM ) ' creates new folder
objExcelApp.ActiveWorkbook.Saveas "E:\REPORTS_EVEREST\" & MNTHNM & "\BATCH_REPORT_" & DT & ".XLS"
End If

Else
Set fso1 = CreateObject("Scripting.FileSystemObject")
Set f = fso1.CreateFolder("E:\REPORTS_EVEREST") ' creates new folder
Set f = fso1.CreateFolder("E:\REPORTS_EVEREST\"& MNTHNM ) ' creates new folder
objExcelApp.ActiveWorkbook.Saveas "E:\REPORTS_EVEREST\" & MNTHNM & "\BATCH_REPORT_" & DT & ".XLS"
End If

objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing

Set objExcelApp2 = CreateObject("Excel.Application")

objExcelApp2.Visible = False

objExcelApp2.Workbooks.Open "D:\BATCH_REPORT.xls"
objExcelApp2.Cells(110,8).Value =""
For i=7 To 107
For j=1 To 30
objExcelApp2.Cells(i,j).Value =""
Next
Next

objExcelApp2.ActiveWorkbook.Save
objExcelApp2.Workbooks.Close
objExcelApp2.Quit
Set objExcelApp2 =Nothing

HMIRuntime.Tags("SHIFT_TRIGGER").Write 0
'MsgBox "File saved successfully."
End If
Back to top
View user's profile Send private message
jingo
Member junior
Member junior


Joined: 19 Oct 2015
Posts: 51
Location: New Mexico

PostPosted: 23/02/2017 16:21    Post subject: Reply with quote

check also this post
http://plc.myforum.ro/how-do-you-export-and-reimport-wincc-runtime-data-vt6472.html
Back to top
View user's profile Send private message
jingo
Member junior
Member junior


Joined: 19 Oct 2015
Posts: 51
Location: New Mexico

PostPosted: 23/02/2017 16:27    Post subject: export data from Alarm Logging and Tag Logging to MS Excel Reply with quote

export data from Alarm Logging and Tag Logging to MS Excel by means of C++.
Here is a c script that works fine for ONE tag from tag logging
Code:
#include "apdefap.h"

int ExportArchiveToCSV2(SYSTEMTIME stStart, SYSTEMTIME stStop, char * ArchiveName, char * VarName, char * FileName)
{
/*
Function exports the values of tag VarName from Tag Logging archive ArchiveName to text file FileName.
Data are exported for the period from stStart to stStop.
Function returns integer value representing the result of export:
0 - Export to file was successfull
2 - No data were received
4 - Can't get data from archive
5 - Can't open text file
*/
#pragma code("pdertcli.dll")
#include "pde_glob.h"
#include "pdertcli.h"
#pragma code()

BOOL retcode, FirstPass = TRUE;
CMN_ERROR error;
int nIndex;
PTLG_ARCHIVDATARAW pDat;
PTLG_ARCHIVDATARAW g_pTlgData = NULL;
DWORD g_TLGdwNumberOfData =10000, g_TLGdwFlags = 0;
FILE * LogFile;

// Open file FileName for write
LogFile = fopen(FileName, "w");
if (LogFile == NULL)
{
// If file was not open report an error and return
printf("ExportArchiveToCSV: Can't open file %s\r\n", FileName);
return 5;
}
printf("ExportArchiveToCSV: file succesfully created:%s\r\n", FileName);

//The cycle that calls ODK function TLGGetArchivDataEx. The cycle is needed because
//this function returns no more than 10000 values. If there are more values in the requested
//period, we need to call this function several times.
do
{
//Adjust maximum number of returned data records before the call
g_TLGdwNumberOfData=10000;
g_pTlgData = NULL;
// Get fata from archive
retcode = TLGGetArchivDataEx(ArchiveName, VarName, &stStart, &stStop, &g_pTlgData,
&g_TLGdwNumberOfData, &g_TLGdwFlags, &error);

// In case of error while getting the data
if ((retcode != TRUE)||(g_pTlgData == NULL))
{
//Output diagnostic message
printf("ExportArchiveToCSV: Error in TLGGetArchivDataEx. %s\r\n",error.szErrorText);
//Free memory
if (g_pTlgData != NULL)
{
retcode = TLGFreeMemory(g_pTlgData);
if (retcode != TRUE)
printf("ExportArchiveToCSV: Error in TLGFreeMemory. %s\r\n",error.szErrorText);
}
//Close text file
fclose(LogFile);
return 4;
}
// If there were no data received
if (g_TLGdwNumberOfData <= 0 )
{
//Output diagnostic message
printf("ExportArchiveToCSV: TLGGetArchivDataEx returned nothing.\r\n");
//Free memory
if (g_pTlgData != NULL)
{
retcode = TLGFreeMemory(g_pTlgData);
if (retcode != TRUE)
printf("ExportArchiveToCSV: Error in TLGFreeMemory. %s\r\n",error.szErrorText);
}
if (FirstPass == FALSE)
// No more points available, but we have already received some data. Everything
//is ok. Exit the cycle
break;
else
{
//If it was the first call to TLGGetArchivDataEx and no data received, than report error code 2 (No data available)
fclose(LogFile);
return 2;
}
}
//Initialize pointer to move through received data
pDat = g_pTlgData;
printf("ExportArchiveToCSV: TLGGetArchivData: Returned %d points.\r\n", g_TLGdwNumberOfData);

//Move through all received data values, and output them to text file, line by line
for (nIndex=0; nIndex<int>stTime.wYear, pDat->stTime.wMonth,
pDat->stTime.wDay, pDat->stTime.wHour, pDat->stTime.wMinute,
pDat->stTime.wSecond, pDat->doValue, pDat->dwFlags);
pDat++;
}
//If function returned 10000 points, than probably more data available.
//So adjust stStart to time of last received data point and repeat the procedure.
if (g_TLGdwNumberOfData >= 10000)
{
PrintToLogFile("ExportArchiveToCSV: More than 10000 points received, going to repeat the call\r\n");
FirstPass = FALSE;
stStart = (pDat - 1)->stTime;
printf("next step\r\n");
}

// Free memory
retcode = TLGFreeMemory(g_pTlgData);
if (retcode != TRUE)
printf("ExportArchiveToCSV: Error in TLGFreeMemory. %s\r\n",error.szErrorText);
}
while (g_TLGdwNumberOfData >= 10000);
//Close file
fclose(LogFile);
return 0;

/* Calling example:
SYSTEMTIME stStart, stStop;
char ArchiveName[255], VarName[255], FileName[255];

stStart.wYear=2007;
stStart.wMonth=3;
stStart.wDay=24;
stStart.wHour=0;
stStart.wMinute=0;
stStart.wSecond=0;
stStart.wMilliseconds=0;

stStop.wYear=2007;
stStop.wMonth=3;
stStop.wDay=24;
stStop.wHour=9;
stStop.wMinute=0;
stStop.wSecond=0;
stStop.wMilliseconds=0;

strcpy(ArchiveName, "ProcessValueArchive");
strcpy(VarName, "CS/Adsorbers/P1_A_103_2.Flt");
strcpy(FileName, "C:\\test.txt");

printf("Returned %d\r\n", ExportArchiveToCSV2 (stStart, stStop, ArchiveName,
VarName, FileName));

*/

}
Back to top
View user's profile Send private message
elay
Junior
Junior


Joined: 23 Feb 2017
Posts: 5

PostPosted: 23/02/2017 17:30    Post subject: Reply with quote

WinCC write to Excel


Code:
Sub OnLButtonDown(Byval Item, Byval Flags, Byval x, Byval y)
Dim objExcelApp
Dim targetRow
Dim tempRow
Dim row
'tempRow =9
'targetRow = 8
For targetRow = 9 To 19


'targetRow =targetRow +row
'tempRow = targetRow
'targetRow =tempRow
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Visible = True

objExcelApp.Workbooks.Open "d:\tenfileexcel.xlsx" (CHON DUONG DAN TOI FILE EXCEL 2007 )
objExcelApp.Cells(2,2).Value = ScreenItems("I/O Field2").OutputValue
objExcelApp.Cells(3,2).Value = ScreenItems("I/O Field3").OutputValue
objExcelApp.Cells(7,2).Value = ScreenItems("I/O Field4").OutputValue
objExcelApp.Cells(targetRow,2).Value = ScreenItems("I/O Field4").OutputValue
objExcelApp.Cells(5,2).Value =Date
'row =row +1
objExcelApp.ActiveWorkbook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing

Next
End Sub
Back to top
View user's profile Send private message
elay
Junior
Junior


Joined: 23 Feb 2017
Posts: 5

PostPosted: 23/02/2017 17:37    Post subject: Reply with quote

Code:

Sub OutputToExcel
Dim wsh, XLSrunning, TargetBookrunning, objExcelApp, objWorkbook, TheTargetBook, TheTargetBookName
Dim TheCount
Set wsh = CreateObject("WScript.Shell")
TheTargetBookName = "report.xls"
TheTargetBook = "D:\Out\" & TheTargetBookName
TheCount = GetObject("winmgmts:root\CIMV2").ExecQuery("SELECT * FROM Win32_Process WHERE Name='EXCEL.EXE'").Count
'While TheCount is bigger than 0, it means the Excel Application is running..., but doesn't mean the workbook is open for sure!
If TheCount > 0 Then
Set objExcelApp = GetObject(,"Excel.Application")
' Using GetObject(,"Excel.Application") to point to the running Excel Application.

TargetBookrunning = 0
For Each XLSrunning in objExcelApp.Workbooks
If XLSrunning.name = TheTargetBookName Then
TargetBookrunning = 1
End If
next
If TargetBookrunning = 1 Then
Set objWorkbook = GetObject(TheTargetBook)
else
Set objWorkbook = objExcelApp.Workbooks.Open(TheTargetBook)
End If
Else

Set objExcelApp = CreateObject("Excel.Application")
Set objWorkbook = objExcelApp.Workbooks.Open(TheTargetBook)

End If

objExcelApp.Visible = true
objExcelApp.ScreenUpdating = True
objExcelApp.DisplayAlerts = True

with objWorkbook.activesheet
.cells(4,2).value = screenItems("IOField1").OutputValue
.cells(4,3).value = screenItems("IOField2").OutputValue
.cells(4,4).value = screenItems("IOField3").OutputValue
End With
objWorkbook.Save
'objWorkbook.Close

Set objWorkbook = Nothing
'objExcelApp.Quit
Set objExcelApp = Nothing
msgbox "Done"

Set wsh = Nothing
End Sub
Back to top
View user's profile Send private message
elay
Junior
Junior


Joined: 23 Feb 2017
Posts: 5

PostPosted: 23/02/2017 17:49    Post subject: Reply with quote

This script opens the excel sheet ==> executes the program ==> closes the excel sheet.

Code:
Sub Read_Write_Excel()

'===========================================================================================================
Dim objXLApp, objXLWb, objXLWs1, objXLWs2

Set objXLApp = CreateObject("Excel.Application")

objXLApp.Visible = True

Set objXLWb = objXLApp.Workbooks.Open("C:\Users\administrator\Documents\MIO481\SCADA_EMS InterfaceV6.xls")

'~~> Working with Sheet1
Set objXLWs1 = objXLWb.Sheets(1)
Set objXLWs2 = objXLWb.Sheets(2)

'~~>Read DHS and RF SetPoints from Sheet1
With objXLWs1

'~~>Read Day Ahead Scheduling(DHS) SetPoints
SmartTags("EMS_to_SCADA_INV_DHS_SP.INV1_ACTIVE_PWR_SP") = .Cells(5,4).value
SmartTags("EMS_to_SCADA_INV_DHS_SP.INV1_REACTIVE_PWR_SP") = .Cells(6,4).value
SmartTags("EMS_to_SCADA_INV_DHS_SP.INV2_ACTIVE_PWR_SP") = .Cells(7,4).value
SmartTags("EMS_to_SCADA_INV_DHS_SP.INV2_REACTIVE_PWR_SP") = .Cells(8,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ActivePwr_PV1") = .Cells(9,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ReActivePwr_PV1") = .Cells(10,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ActivePwr_PV2") = .Cells(11,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ReActivePwr_PV2") = .Cells(12,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ActivePwr_PV3") = .Cells(13,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ReActivePwr_PV3") = .Cells(14,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ActivePwr_PV4") = .Cells(15,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ReActivePwr_PV4") = .Cells(16,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ActivePwr_PV5") = .Cells(17,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ReActivePwr_PV5") = .Cells(18,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ActivePwr_PV6") = .Cells(19,4).value
SmartTags("EMS_to_SCADA_PV_INV_DHS_SP.ReActivePwr_PV6") = .Cells(20,4).value

'~~>Read Rolling Forecast(RF) Setpoints
SmartTags("EMS_to_SCADA_INV_RF_SP.INV1_ACTIVE_PWR_SP") = .Cells(23,4).value
SmartTags("EMS_to_SCADA_INV_RF_SP.INV1_REACTIVE_PWR_SP") = .Cells(24,4).value
SmartTags("EMS_to_SCADA_INV_RF_SP.INV2_ACTIVE_PWR_SP") = .Cells(25,4).value
SmartTags("EMS_to_SCADA_INV_RF_SP.INV2_REACTIVE_PWR_SP") = .Cells(26,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ActivePwr_PV1") = .Cells(27,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ReActivePwr_PV1") = .Cells(28,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ActivePwr_PV2") = .Cells(29,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ReActivePwr_PV2") = .Cells(30,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ActivePwr_PV3") = .Cells(31,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ReActivePwr_PV3") = .Cells(32,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ActivePwr_PV4") = .Cells(33,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ReActivePwr_PV4") = .Cells(34,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ActivePwr_PV5") = .Cells(35,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ReActivePwr_PV5") = .Cells(36,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ActivePwr_PV6") = .Cells(37,4).value
SmartTags("EMS_to_SCADA_PV_INV_RF_SP.ReActivePwr_PV6") = .Cells(38,4).value

'~~>Read PV Inverters ON/OFF Status
SmartTags("EMS_to_SCADA_PV_INV_Status.PV_INV1") = .Cells(41,4).value
SmartTags("EMS_to_SCADA_PV_INV_Status.PV_INV2") = .Cells(42,4).value
SmartTags("EMS_to_SCADA_PV_INV_Status.PV_INV3") = .Cells(43,4).value
SmartTags("EMS_to_SCADA_PV_INV_Status.PV_INV4") = .Cells(44,4).value
SmartTags("EMS_to_SCADA_PV_INV_Status.PV_INV5") = .Cells(45,4).value
SmartTags("EMS_to_SCADA_PV_INV_Status.PV_INV6") = .Cells(46,4).value

End With

''~~>Write SetPoints/Initial Setup Values to Sheet2
With objXLWs2

'~~>Write
.Cells(4,4).value = SmartTags("InverterToScada_Inv1.activePwrActInv")
.Cells(5,4).value = SmartTags("InverterToScada_Inv1.reactPwrActualInv")
.Cells(6,4).value = SmartTags("InitialSetup_Inverter1.InvKWLimit")
.Cells(7,4).value = SmartTags("InverterToScada_Inv2.activePwrActInv")
.Cells(8,4).value = SmartTags("InverterToScada_Inv2.reactPwrActualInv")
.Cells(9,4).value = SmartTags("InitialSetup_Inverter2.InvKWLimit")
.Cells(10,4).value = SmartTags("InverterToScada_BMS1.batSOC")
.Cells(11,4).value = SmartTags("InverterToScada_BMS2.batSOC")
.Cells(12,4).value = SmartTags("InverterToScada_BMS1.imd")
.Cells(13,4).value = SmartTags("InverterToScada_BMS1.imr")
.Cells(14,4).value = SmartTags("12KV_CB_CLOSE")
.Cells(15,4).value = SmartTags("12KV_CB_OPEN")
.Cells(16,4).value = SmartTags("InverterToScada_Inv1.Inv_enabled")
.Cells(17,4).value = SmartTags("InverterToScada_Inv2.Inv_enabled")
.Cells(18,4).value = SmartTags("SCADA_to_EMS_PV_Inv_Status.PV_INV1")
.Cells(19,4).value = SmartTags("SCADA_to_EMS_PV_Inv_Status.PV_INV2")
.Cells(20,4).value = SmartTags("SCADA_to_EMS_PV_Inv_Status.PV_INV3")
.Cells(21,4).value = SmartTags("SCADA_to_EMS_PV_Inv_Status.PV_INV4")
.Cells(22,4).value = SmartTags("SCADA_to_EMS_PV_Inv_Status.PV_INV5")
.Cells(23,4).value = SmartTags("SCADA_to_EMS_PV_Inv_Status.PV_INV6")
.Cells(24,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ActivePwr_PV1")
.Cells(25,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ReActivePwr_PV1")
.Cells(26,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ActivePwr_PV2")
.Cells(27,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ReActivePwr_PV2")
.Cells(28,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ActivePwr_PV3")
.Cells(29,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ReActivePwr_PV3")
.Cells(30,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ActivePwr_PV4")
.Cells(31,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ReActivePwr_PV4")
.Cells(32,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ActivePwr_PV5")
.Cells(33,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ReActivePwr_PV5")
.Cells(34,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ActivePwr_PV6")
.Cells(35,4).value = SmartTags("SCADA_to_EMS_PV_INV_PQ_Act.ReActivePwr_PV6")
.Cells(36,4).value = SmartTags("SCADA_to_EMS_Meter_Reading.Total_Demand_KW")
.Cells(37,4).value = SmartTags("SCADA_to_EMS_Meter_Reading.Desired_PF")
.Cells(38,4).value = SmartTags("SCADA_to_EMS_Meter_Reading.Total_Demand_KVAR")

End With

'~~> Save as Excel File (xls) to retain format
objXLWb.Save

objXLWb.Close (False)

Set objXLWs1 = Nothing
Set objXLWs2 = Nothing
Set objXLWb = Nothing

objXLApp.Quit
Set objXLApp = Nothing


use following ladder logic for executing the below script every minute. In the HMI,You can use %M20.0 and in tag properties 'upon value change' the script will be executed.
wincc to excel sheet Re: wincc to excel sheet
Back to top
View user's profile Send private message
deray88
Junior 2
Junior 2
deray88

Joined: 30 Jul 2014
Posts: 22
Location: chile

PostPosted: 28/08/2018 20:21    Post subject: Reply with quote

Voy a probar y comento...

elay wrote:
WinCC write to Excel


Code:
Sub OnLButtonDown(Byval Item, Byval Flags, Byval x, Byval y)
Dim objExcelApp
Dim targetRow
Dim tempRow
Dim row
'tempRow =9
'targetRow = 8
For targetRow = 9 To 19


'targetRow =targetRow +row
'tempRow = targetRow
'targetRow =tempRow
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Visible = True

objExcelApp.Workbooks.Open "d:\tenfileexcel.xlsx" (CHON DUONG DAN TOI FILE EXCEL 2007 )
objExcelApp.Cells(2,2).Value = ScreenItems("I/O Field2").OutputValue
objExcelApp.Cells(3,2).Value = ScreenItems("I/O Field3").OutputValue
objExcelApp.Cells(7,2).Value = ScreenItems("I/O Field4").OutputValue
objExcelApp.Cells(targetRow,2).Value = ScreenItems("I/O Field4").OutputValue
objExcelApp.Cells(5,2).Value =Date
'row =row +1
objExcelApp.ActiveWorkbook.Save
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing

Next
End Sub
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    plc.myforum.ro Forum Index -> Simatic Automation Systems All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro