I am a beginner i vbs and need som help! I have a problem with my script.
info:
OS Windows 10 and server 2012
VBS is written in WinCC from Siemens
OpenOffice 4.1.2 Calc
I have a vb script that moves som values to a calc spreedsheat and all this works
but i can't get it to print the spreedsheat out.
My code so fare
Code: Select all
Sub OnClick(ByVal Item)
Dim WinCCTag
Dim TankNr
Dim objTag
Dim Year
Dim Month
Dim Day
Dim Dato
Dim Tid
Dim objPopup
Dim sMO
Dim oD
Dim wb
Dim oSheet
'Lave dato til file navn
Year = DatePart("yyyy",Date,vbMonday,vbFirstFourDays)
Month = DatePart("m",Date,vbMonday,vbFirstFourDays)
Day = DatePart("D",Date,vbMonday,vbFirstFourDays)
Dato = Year & Month & Day & Hour(Now) & Minute(Now) & Second (Now)
'Hente Tank nr.
Set TankNr = HMIRuntime.Tags("Lokal.TankNR")
TankNr.Read
'Åben OpenOffice Calc
Set sMO = CreateObject("com.sun.star.ServiceManager") 'To open the Sun Server
Set oD = sMO.createInstance("com.sun.star.frame.Desktop") 'To open the Desktop
Set wb = oD.loadComponentFromURL("file:///C:\Projekt\Div\Tank_Parameter\Master\Parameter_Master_Tank.ods", "_blank", 0, Array())
Set oSheet = wb.CurrentController.ActiveSheet
'Skriv data til rapporten
oSheet.getCellByPosition( 3, 4 ).String = Day & "." & MonthName (Month) & " " & Year
oSheet.getCellByPosition( 3, 5 ).String = Hour(Now) & ":" & Minute(Now) & ":" & Second (Now)
oSheet.getCellByPosition( 3, 6 ).String = TankNr.Value
Set WinCCTag = HMIRuntime.Tags("Lokal.Gruppe")
WinCCTag.Read
oSheet.getCellByPosition(3, 8).String = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags("Lokal.Kunde")
WinCCTag.Read
oSheet.getCellByPosition(3, 9).String = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags("Lokal.Produkt")
WinCCTag.Read
oSheet.getCellByPosition(3, 10).String = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags("Lokal.A_Maal")
WinCCTag.Read
oSheet.getCellByPosition(3,12).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags("Lokal.Diameter")
WinCCTag.Read
oSheet.getCellByPosition(3,13).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags("Lokal.Hoejde")
WinCCTag.Read
oSheet.getCellByPosition(3, 14).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".BundVolumen")
WinCCTag.Read
oSheet.getCellByPosition(3, 15).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags("_Norminel_Niveau_SP")
WinCCTag.Read
oSheet.getCellByPosition(3, 16).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Density")
WinCCTag.Read
oSheet.getCellByPosition(3, 18).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Tank_Aktiv")
WinCCTag.Read
If WinCCTag.Value = 1 Then
oSheet.getCellByPosition(3, 20).String = "Til"
Else
oSheet.getCellByPosition(3, 20).String = "Fra"
End If
Set WinCCTag = HMIRuntime.Tags(".Niveau_SP")
WinCCTag.Read
oSheet.getCellByPosition(7, 14).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Niveau_Dif_Tons")
WinCCTag.Read
oSheet.getCellByPosition(7, 15).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Niveau_Dif_Tid_Min")
WinCCTag.Read
oSheet.getCellByPosition(7, 16).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags("_HurtigNiveau_Dif_Tons")
WinCCTag.Read
oSheet.getCellByPosition(7, 17).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags("_HurtigNiveau_Dif_Tid_Min")
WinCCTag.Read
oSheet.getCellByPosition(7, 18).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".HH_AlarmLimit")
WinCCTag.Read
oSheet.getCellByPosition(7, 20).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".H_AlarmLimit")
WinCCTag.Read
oSheet.getCellByPosition(7, 21).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".L_AlarmLimit")
WinCCTag.Read
oSheet.getCellByPosition(7, 22).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".LL_AlarmLimit")
WinCCTag.Read
oSheet.getCellByPosition(7, 23).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Tons")
WinCCTag.Read
oSheet.getCellByPosition(7, 25).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".VCF")
WinCCTag.Read
oSheet.getCellByPosition(7, 26).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Produkt_25C")
WinCCTag.Read
oSheet.getCellByPosition(7, 27).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Max_Volumen")
WinCCTag.Read
oSheet.getCellByPosition(7, 28).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Niveau")
WinCCTag.Read
oSheet.getCellByPosition(7, 8).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Volumen")
WinCCTag.Read
oSheet.getCellByPosition(7, 9).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Temp")
WinCCTag.Read
oSheet.getCellByPosition(7, 10).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Flow")
WinCCTag.Read
oSheet.getCellByPosition(7, 11).Value = WinCCTag.Value
Set WinCCTag = HMIRuntime.Tags(".Tid_Fuld")
WinCCTag.Read
oSheet.getCellByPosition(7, 12).Value = WinCCTag.Value
On Error Resume Next
'Print
CallByName oSheet, "Print", vbMethod, Array() ------------------------------------------------------------------------------------------------- Help her
'Saving the document With completed status To a New file.
Call oSheet.StoreToURL("file:///C:\Projekt/Div/Tank_Parameter/" & TankNr.Value & "/" & TankNr.Value & "_" & Dato & ".ods", Array())
'Closing the document.
oSheet.Close (True)
Set wb = Nothing
Set oSM = Nothing
Set oD = Nothing
Set oSheet = Nothing
End Sub