EZDOL
Üye
- Katılım
- 7 Mar 2019
- Mesajlar
- 7
- Puanları
- 1
- Yaş
- 30
merhaba arkadaşlar wincc flexible da yazılmış bir script var kantardan gecen kütükleerin kglarını otomatik olarak excele yazdırıyor. fakat biz bunu gün gün excel dosyası olarak yazdırmak istiyoruz. birçok komut denedim araştırdığım yerlerde yazanlarla hiçbiri olmadı. nerede yanlış yaptığımı anlayamadım. çok bilgiye sahip değilim araştırarak yapmaya çalışıyorum fakat bir yerlerde kaçırdığım şeyler var sanırım. yardımcı olursanız çok sevinirim.
NOTE: To start scripting please press <Ctrl><Space> and see the wide variety of functions.
'Write scripts by using system functions or the WinCC flexible object model. You can easily access to the
'system through the HMI runtime object. For a convenient picking of an object reference
'you can press <Alt><Right Arrow>. Design complex scripts by employing the basic features
'of the programming language VBScript and access tags directly by name e.g. tag = 5.
Dim b1, b1_ok
Dim gen_ok
Dim dir_d, temp_f, cur_f, fok
Dim objApp
Dim TheCount, TargetBookrunning, XLSrunning, objWork
Dim objFSO
Const OverwriteExisting = 1
Dim curSira, curRow
Dim b1_name, b1_ok_name
b1_name = "kayıt_al"
b1_ok_name = "kayıt_ok"
b1 = SmartTags(b1_name).Value
b1_ok = SmartTags(b1_ok_name).Value
gen_ok = False ' (b1 And (Not b1_ok))
If (b1 And (Not b1_ok)) Then
gen_ok = True
End If
If gen_ok Then
dir_d = "d:\agirlik_rapor\"
temp_f = "agirlik_template.xlsx"
cur_f = Year(Now) & "_" & Month(Now) & "_" & Day(Now) & "_rapor.xlsx"
fok = file_ok(dir_d & cur_f)
If Not fok Then
' file yok
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FileExists(dir_d & cur_f) Then
objFSO.CopyFile dir_d & temp_f, dir_d & cur_f, OverwriteExisting
HmiRuntime.Trace "Dosya : " & dir_d & cur_f & " yok." & vbCrLf & ". Yeniden yaratıldı." & vbCrLf
End If
Set objFSO = Nothing
End If
fok = file_ok(dir_d & cur_f)
If fok Then
' file var
TheCount = GetObject("winmgmts:root\CIMV2").ExecQuery("SELECT * FROM Win32_Process WHERE Name='EXCEL.EXE'").Count
If TheCount > 0 Then
Set objApp = GetObject(,"Excel.Application")
' Using GetObject(,"Excel.Application") to point to the running Excel Application.
TargetBookrunning = 0
For Each XLSrunning In objApp.Workbooks
If XLSrunning.name = cur_f Then
TargetBookrunning = 1
End If
Next
If TargetBookrunning = 1 Then
Set objWork = GetObject(dir_d & cur_f)
Else
Set objWork = objApp.Workbooks.Open(dir_d & cur_f)
End If
Else
Set objApp = CreateObject("Excel.Application")
Set objWork = objApp.Workbooks.Open(dir_d & cur_f)
End If ' TheCount
objApp.Visible = False
'objApp.ScreenUpdating = False
objApp.DisplayAlerts = False
Else
Exit Sub
End If
If b1 Then
' curSira = objWork.ActiveSheet.Cells(1,1).Value
curRow = objWork.ActiveSheet.Cells(1,2).Value
objWork.ActiveSheet.Cells(curRow, 1) = objWork.ActiveSheet.Cells(1,1).Value
objWork.ActiveSheet.Cells(curRow, 2) = SmartTags("agirlik")
objWork.ActiveSheet.Cells(curRow, 3) = Time
SmartTags(b1_name).Value = False
SmartTags(b1_ok_name).Value = True
End If
If fok Then
objWork.Save
objWork.Close
Set objWork = Nothing
objApp.Quit
Set objApp = Nothing
HmiRuntime.Trace "Done !!!" & vbCrLf
End If
NOTE: To start scripting please press <Ctrl><Space> and see the wide variety of functions.
'Write scripts by using system functions or the WinCC flexible object model. You can easily access to the
'system through the HMI runtime object. For a convenient picking of an object reference
'you can press <Alt><Right Arrow>. Design complex scripts by employing the basic features
'of the programming language VBScript and access tags directly by name e.g. tag = 5.
Dim b1, b1_ok
Dim gen_ok
Dim dir_d, temp_f, cur_f, fok
Dim objApp
Dim TheCount, TargetBookrunning, XLSrunning, objWork
Dim objFSO
Const OverwriteExisting = 1
Dim curSira, curRow
Dim b1_name, b1_ok_name
b1_name = "kayıt_al"
b1_ok_name = "kayıt_ok"
b1 = SmartTags(b1_name).Value
b1_ok = SmartTags(b1_ok_name).Value
gen_ok = False ' (b1 And (Not b1_ok))
If (b1 And (Not b1_ok)) Then
gen_ok = True
End If
If gen_ok Then
dir_d = "d:\agirlik_rapor\"
temp_f = "agirlik_template.xlsx"
cur_f = Year(Now) & "_" & Month(Now) & "_" & Day(Now) & "_rapor.xlsx"
fok = file_ok(dir_d & cur_f)
If Not fok Then
' file yok
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FileExists(dir_d & cur_f) Then
objFSO.CopyFile dir_d & temp_f, dir_d & cur_f, OverwriteExisting
HmiRuntime.Trace "Dosya : " & dir_d & cur_f & " yok." & vbCrLf & ". Yeniden yaratıldı." & vbCrLf
End If
Set objFSO = Nothing
End If
fok = file_ok(dir_d & cur_f)
If fok Then
' file var
TheCount = GetObject("winmgmts:root\CIMV2").ExecQuery("SELECT * FROM Win32_Process WHERE Name='EXCEL.EXE'").Count
If TheCount > 0 Then
Set objApp = GetObject(,"Excel.Application")
' Using GetObject(,"Excel.Application") to point to the running Excel Application.
TargetBookrunning = 0
For Each XLSrunning In objApp.Workbooks
If XLSrunning.name = cur_f Then
TargetBookrunning = 1
End If
Next
If TargetBookrunning = 1 Then
Set objWork = GetObject(dir_d & cur_f)
Else
Set objWork = objApp.Workbooks.Open(dir_d & cur_f)
End If
Else
Set objApp = CreateObject("Excel.Application")
Set objWork = objApp.Workbooks.Open(dir_d & cur_f)
End If ' TheCount
objApp.Visible = False
'objApp.ScreenUpdating = False
objApp.DisplayAlerts = False
Else
Exit Sub
End If
If b1 Then
' curSira = objWork.ActiveSheet.Cells(1,1).Value
curRow = objWork.ActiveSheet.Cells(1,2).Value
objWork.ActiveSheet.Cells(curRow, 1) = objWork.ActiveSheet.Cells(1,1).Value
objWork.ActiveSheet.Cells(curRow, 2) = SmartTags("agirlik")
objWork.ActiveSheet.Cells(curRow, 3) = Time
SmartTags(b1_name).Value = False
SmartTags(b1_ok_name).Value = True
End If
If fok Then
objWork.Save
objWork.Close
Set objWork = Nothing
objApp.Quit
Set objApp = Nothing
HmiRuntime.Trace "Done !!!" & vbCrLf
End If