Professional Documents
Culture Documents
F Parag PC Data e Drive Inox Reports Xls Application Note Mis Reports in Excel
F Parag PC Data e Drive Inox Reports Xls Application Note Mis Reports in Excel
1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Offenders will be liable for damages. All rights, including rights created by patent
grant or registration of a utility model or design, are reserved.
Page 1 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Document History
Page 2 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Table of Contents
Page 3 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Purpose
The purpose of this document is to act as a reference for the
development and implementation of the Daily/Batch report system
for production, consumption etc. for a plant/process. This
document will be helpful for the system engineers as a quick
reference and a ready solution that can be easily implemented with
less engineering effort & cost.
Scope
This application note explains the procedure of implementation of
the MIS reports in excel for the daily production and consumption
of the products. It gives an hourly record of the products
consumption status. The implementation procedure herein includes
the basic scripting used for the generation of such report from
WinCC.
Page 4 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
1. Introduction
Overview:
Page 5 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
2. Client Requirements
Page 6 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Here in this report we need to login the details of the flow totalizers
at the end of every hour as seen in the format above. At the every
day 10:00 PM the excel sheet has to be generated with that date.
The column of total will give the consumption at any point of time.
For e.g. if the excel sheet is opened at 11:30 AM then the total will
show the consumption till 11:00 AM.
Page 7 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
3. Solution
Requirements for PCS7:
The solution provided for the above requirement from the client will
also have some prerequisites for the PCS7 system from where the
report is to be generated.
The prerequisites are as follows:
Creating a template:
Page 8 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Page 9 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Dim RowNo
Dim a
Dim M2_MODE, M3_MODE,M4_MODE, DEL
Dim objExcelApp,objExcelApp2
Dim fso
Dim fso1, f,fName
Dim i,x,y,z,p,q
Dim FileNameX
i = Hour(Now())
x = Day(Now())
y = Month(Now())
z = Year(Now())
• Part1: Checking & creating the active excel file to update the tag values.
If (fso.FileExists("D:\HOURLY_RPT.xls")) Then
Else
'****** If working file (HOURLY_RPT.xls) does not exists then create it *********
'****** Open the Template (Read only & Hidden file on the mentioned path) ******
objExcelApp.Workbooks.Open "D:\DAILY_RPT.xlt"
objExcelApp.DisplayAlerts = False
objExcelApp.ActiveWorkbook.Saveas"D:\HOURLY_RPT.xls"
'objExcelApp.ActiveWorkbook.Save '"D:\HOURLY_RPT.xls"
objExcelApp.DisplayAlerts = False
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing
End If
Page 10 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
If i = 22 Then
RowNo = 34
objExcelApp.Cells(RowNo,2) = Date()
objExcelApp.Cells(RowNo,3) = Time()
objExcelApp.Cells(RowNo,4).Value =HMIRuntime.Tags("FI7800/FI_7800_TOTAL.V").Read
objExcelApp.Cells(RowNo,5).Value =HMIRuntime.Tags("FI7851/FI_7851_TOTAL.V").Read
objExcelApp.Cells(RowNo,6).Value =HMIRuntime.Tags("FI7852/FI_7852_TOTAL.V").Read
objExcelApp.Cells(RowNo,7).Value =HMIRuntime.Tags("FI7853/FI_7853_TOTAL.V").Read
objExcelApp.Cells(RowNo,8).Value =HMIRuntime.Tags("FI7854/FI_7854_TOTAL.V").Read
'objExcelApp.Cells(RowNo,9).Value =HMIRuntime.Tags("TAGNAME").Read
objExcelApp.Cells(RowNo,10).Value =HMIRuntime.Tags("FI6800/FI_6800_TOTAL.V").Read
objExcelApp.Cells(RowNo,11).Value =HMIRuntime.Tags("FI2040/FI_2040_TOTAL.V").Read
objExcelApp.Cells(RowNo,12).Value =HMIRuntime.Tags("FI6951/FI6951_TOTAL.V").Read
objExcelApp.Cells(RowNo,13).Value =HMIRuntime.Tags("FI6952/FI6952_TOTAL.V").Read
objExcelApp.Cells(RowNo,14).Value =HMIRuntime.Tags("FI6852/FI_6852_TOTAL.V").Read
'objExcelApp.Cells(i,15).Value =HMIRuntime.Tags("TAGNAME").Read
'objExcelApp.Cells(i,16).Value =HMIRuntime.Tags("TAGNAME").Read
Page 11 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
FileNameX = "D:\MIS\MIS_" & x & "-" & y & "-" & z & ".xls"
objExcelApp.DisplayAlerts = False
objExcelApp.ActiveWorkbook.SaveAs (FileNameX)
objExcelApp.DisplayAlerts = False
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing
End If
'** Select the particular row of excel sheet to be updated based of the current hour *
Select Case i
Case 22 : RowNo = 10
Case 23 : RowNo = 11
Case 0 : RowNo = 12
Case 1 : RowNo = 13
Case 2 : RowNo = 14
Case 3 : RowNo = 15
Case 4 : RowNo = 16
Case 5 : RowNo = 17
Case 6 : RowNo = 18
Case 7 : RowNo = 19
Case 8 : RowNo = 20
Case 9 : RowNo = 21
Case 10 : RowNo = 22
Case 11 : RowNo = 23
Case 12 : RowNo = 24
Case 13 : RowNo = 25
Case 14 : RowNo = 26
Case 15 : RowNo = 27
Case 16 : RowNo = 28
Case 17 : RowNo = 29
Case 18 : RowNo = 30
Case 19 : RowNo = 31
Case 20 : RowNo = 32
Case 21 : RowNo = 33
End Select
Page 12 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
objExcelApp.Workbooks.Open "D:\HOURLY_RPT.xls"
objExcelApp.Cells(RowNo,2) = Date()
objExcelApp.Cells(RowNo,3) = Time()
objExcelApp.Cells(RowNo,4).Value =HMIRuntime.Tags("FI7800/FI_7800_TOTAL.V").Read
objExcelApp.Cells(RowNo,5).Value =HMIRuntime.Tags("FI7851/FI_7851_TOTAL.V").Read
objExcelApp.Cells(RowNo,6).Value =HMIRuntime.Tags("FI7852/FI_7852_TOTAL.V").Read
objExcelApp.Cells(RowNo,7).Value =HMIRuntime.Tags("FI7853/FI_7853_TOTAL.V").Read
objExcelApp.Cells(RowNo,8).Value =HMIRuntime.Tags("FI7854/FI_7854_TOTAL.V").Read
'objExcelApp.Cells(RowNo,9).Value =HMIRuntime.Tags("TAGNAME").Read
objExcelApp.Cells(RowNo,10).Value =HMIRuntime.Tags("FI6800/FI_6800_TOTAL.V").Read
objExcelApp.Cells(RowNo,11).Value =HMIRuntime.Tags("FI2040/FI_2040_TOTAL.V").Read
objExcelApp.Cells(RowNo,12).Value =HMIRuntime.Tags("FI6951/FI6951_TOTAL.V").Read
objExcelApp.Cells(RowNo,13).Value =HMIRuntime.Tags("FI6952/FI6952_TOTAL.V").Read
objExcelApp.Cells(RowNo,14).Value =HMIRuntime.Tags("FI6852/FI_6852_TOTAL.V").Read
'objExcelApp.Cells(i,15).Value =HMIRuntime.Tags("TAGNAME").Read
'objExcelApp.Cells(i,16).Value =HMIRuntime.Tags("TAGNAME").Read
objExcelApp.DisplayAlerts = False
objExcelApp.ActiveWorkbook.Save
objExcelApp.DisplayAlerts = False
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing
• Part 4: Refreshing the active Excel to clear all the entries other than 10:00
PM.
Page 13 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
If i = 22 Then
objExcelApp2.Visible = False
objExcelApp2.Workbooks.Open "D:\HOURLY_RPT.xls"
For p=11 To 37
For q=1 To 16
objExcelApp2.Cells(p,q).Value =""
Next
Next
objExcelApp2.ActiveWorkbook.Save
objExcelApp2.Workbooks.Close
objExcelApp2.Quit
Set objExcelApp2 =Nothing
End If
End Function
Script Functioning:
The above script checks for the availability of the current excel file
to be updated (HOURLY_RPT.xls) at every trigger. If the file is not
found it creates the file with the name “HOURLY_RPT.xls” in the
“D:\” drive. With respect to the hour at which the script is
triggered it selects the specific row and as per the template
updates the values of the respective tags in the cells of the row
selected. At 10:00 PM every day script updates the entry in the
cells of Row no. 34 and then saves the file with the name
“MIS_DD-MM-YYYY.xls” at the location “D:\MIS\”. Also at
10:00 PM after saving the file it selects the Row no. as per the hour
and updates the respective cells. It also clears all the remaining
entries in the current excel file.
Page 14 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Configuring Reports:
Page 15 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
• Set a cyclic trigger to the script so that the excel report gets
updated every hour. The same is shown in the figure below.
Page 16 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
4. Additional Features:
Reset of Tag Value:
Dim i,Rowno
Dim ObjExcelApp
HMIRuntime.Tags("FI7800/RST_FI7800_TOTAL.I0").Write 0
objExcelApp.Cells(36,2).Value = "Reset"
objExcelApp.Cells(36,4).Value =HMIRuntime.Tags("FI7800/FI_7800_TOTAL.V").Read
‘************* Check the Hour to compare the last value in the Excel *********
i = Hour(Now())
Select Case i
Case 22 : RowNo = 10
Case 23 : RowNo = 11
Case 0 : RowNo = 12
Page 17 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Case 1 : RowNo = 13
Case 2 : RowNo = 14
Case 3 : RowNo = 15
Case 4 : RowNo = 16
Case 5 : RowNo = 17
Case 6 : RowNo = 18
Case 7 : RowNo = 19
Case 8 : RowNo = 20
Case 9 : RowNo = 21
Case 10 : RowNo = 22
Case 11 : RowNo = 23
Case 12 : RowNo = 24
Case 13 : RowNo = 25
Case 14 : RowNo = 26
Case 15 : RowNo = 27
Case 16 : RowNo = 28
Case 17 : RowNo = 29
Case 18 : RowNo = 30
Case 19 : RowNo = 31
Case 20 : RowNo = 32
Case 21 : RowNo = 33
End Select
HMIRuntime.Tags("FI7800/RST_FI7800_TOTAL.I0").Write 1
MsgBox( RowNo )
objExcelApp.DisplayAlerts = False
objExcelApp.ActiveWorkbook.Save
objExcelApp.DisplayAlerts = False
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing
End Sub
‘**************************** END ***************************
For different tags different reset buttons were created. The same
script was used by changing the respective tag name and the cell
reference for the reset value and the difference value to be
updated as per the template.
Page 18 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Auto Reset:
Along with the manual reset provided for individual tags, there is a
script in function which will reset the tag values at a specific date
and time every month/year. This script will also update the same
Reset row with the tag values at the time of reset and will
calculate the total considering the difference in the reset value and
value captured during the last hour.
Dim i
Dim RowNo
Dim objExcelApp
HMIRuntime.Tags("FI7800/RST_FI7800_TOTAL.I0").Write 0
HMIRuntime.Tags("FI7851/RST_FI7851_TOTAL.I0").Write 0
HMIRuntime.Tags("FI7854/RST_FI7854_TOTAL.I0").Write 0
HMIRuntime.Tags("FI7852/RST_FI7852_TOTAL.I0").Write 0
HMIRuntime.Tags("FI7853/RST_FI7853_TOTAL.I0").Write 0
HMIRuntime.Tags("FI2040/RST_FI2040_TOTAL.I0").Write 0
HMIRuntime.Tags("FI6800/RST_FI6800_TOTAL.I0").Write 0
HMIRuntime.Tags("FI6951/RST_FI6951_TOTAL.I0").Write 0
HMIRuntime.Tags("FI6852/RST_FI6852_TOTAL.I0").Write 0
HMIRuntime.Tags("FI6952/RST_FI6952_TOTAL.I0").Write 0
Page 19 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
objExcelApp.Workbooks.Open "D:\HOURLY_RPT.xls"
objExcelApp.Cells(36,2).Value = "Reset"
objExcelApp.Cells(36,4).Value =HMIRuntime.Tags("FI7800/FI_7800_TOTAL.V").Read
objExcelApp.Cells(36,5).Value =HMIRuntime.Tags("FI7851/FI_7851_TOTAL.V").Read
objExcelApp.Cells(36,6).Value =HMIRuntime.Tags("FI7852/FI_7852_TOTAL.V").Read
objExcelApp.Cells(36,7).Value =HMIRuntime.Tags("FI7853/FI_7853_TOTAL.V").Read
objExcelApp.Cells(36,8).Value =HMIRuntime.Tags("FI7854/FI_7854_TOTAL.V").Read
'objExcelApp.Cells(36,9).Value =HMIRuntime.Tags("TAGNAME").Read
objExcelApp.Cells(36,10).Value =HMIRuntime.Tags("FI6800/FI_6800_TOTAL.V").Read
objExcelApp.Cells(36,11).Value =HMIRuntime.Tags("FI2040/FI_2040_TOTAL.V").Read
objExcelApp.Cells(36,12).Value =HMIRuntime.Tags("FI6951/FI6951_TOTAL.V").Read
objExcelApp.Cells(36,13).Value =HMIRuntime.Tags("FI6952/FI6952_TOTAL.V").Read
objExcelApp.Cells(36,14).Value =HMIRuntime.Tags("FI6852/FI_6852_TOTAL.V").Read
'objExcelApp.Cells(36,15).Value =HMIRuntime.Tags("TAGNAME").Read
'objExcelApp.Cells(36,16).Value =HMIRuntime.Tags("TAGNAME").Read
‘************* Check the Hour to compare the last value in the Excel *********
i = Hour(Now())
Select Case i
Case 22 : RowNo = 10
Case 23 : RowNo = 11
Case 0 : RowNo = 12
Case 1 : RowNo = 13
Case 2 : RowNo = 14
Case 3 : RowNo = 15
Case 4 : RowNo = 16
Case 5 : RowNo = 17
Case 6 : RowNo = 18
Case 7 : RowNo = 19
Case 8 : RowNo = 20
Case 9 : RowNo = 21
Case 10 : RowNo = 22
Page 20 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
Case 11 : RowNo = 23
Case 12 : RowNo = 24
Case 13 : RowNo = 25
Case 14 : RowNo = 26
Case 15 : RowNo = 27
Case 16 : RowNo = 28
Case 17 : RowNo = 29
Case 18 : RowNo = 30
Case 19 : RowNo = 31
Case 20 : RowNo = 32
Case 21 : RowNo = 33
End Select
HMIRuntime.Tags("FI7800/RST_FI7800_TOTAL.I0").Write 1
HMIRuntime.Tags("FI7851/RST_FI7851_TOTAL.I0").Write 1
HMIRuntime.Tags("FI7854/RST_FI7854_TOTAL.I0").Write 1
HMIRuntime.Tags("FI7852/RST_FI7852_TOTAL.I0").Write 1
Page 21 of 22
SIEMENS Version: 0.1
Application Note:
I IA AS SP E&C
MIS Reports in Excel
HMIRuntime.Tags("FI7853/RST_FI7853_TOTAL.I0").Write 1
HMIRuntime.Tags("FI2040/RST_FI2040_TOTAL.I0").Write 1
HMIRuntime.Tags("FI6800/RST_FI6800_TOTAL.I0").Write 1
HMIRuntime.Tags("FI6951/RST_FI6951_TOTAL.I0").Write 1
HMIRuntime.Tags("FI6852/RST_FI6852_TOTAL.I0").Write 1
HMIRuntime.Tags("FI6952/RST_FI6952_TOTAL.I0").Write 1
MsgBox( RowNo )
objExcelApp.DisplayAlerts = False
objExcelApp.ActiveWorkbook.Save
objExcelApp.DisplayAlerts = False
objExcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing
End Function
Page 22 of 22