Hi,
I have a problem about "run a script" via Event Manager. I'm pretty sure that the problem is due to Win7 OS. But I don't know exactly how i can fix it and also i'm not sure which security parameter(s) i have to change.
Basically I want to open an excel file with a basic script via event manager. Script is time-based and it must run every hour.
When script triggered , I'm checking the script using BCE User Interface and I see the error at line X ( The code on line X is obj.Workbooks.Open filename:="C:\Program Files\Proficy\Proficy CIMPLICITY\projects\BUSEB\report\Hr_Rep.xlsm"
). But, when i run code manually there is no problem. Problem occurs only when script is triggered from event manager.
I also changed some parameters on windows 7.
1-control panel-->user acconts-->change user account control--> Set to "never notify"
2-control panel-->Admisitrative Services-->Services-->Interactive Services--> set to "Disable"
As I said before, the problem is sourced from Win7 Operating System. So, maybe anyone knows which security parameters should i change on OS?
The code is:
Sub Main()
Dim obj As Object
Dim iDay,iMonth,iYear,iHour,iRepStat,iRepType As Integer
Dim bPagePrint As Boolean
Dim strPrinterName As String
Dim tReal As Double
bPagePrint = PointGet("VIR.B0[0]")
strPrinterName =PointGet("vir.rep_printer")
iDay=datepart("d",(Date))
iMonth=datepart("m",(Date))
iYear=year(Date)
iHour=hour(now)
Call CheckFileIsOpen 'Check excel file is open?
Set obj=createobject("excel.application")
obj.Workbooks.Open filename:="C:\Program Files\Proficy\Proficy CIMPLICITY\projects\BUSEB\report\Hr_Rep.xlsm"
obj.application.displayalerts=false
obj.visible=false
obj.activeworkbook.sheets("set").select
obj.ActiveSheet.Range("A1")=iYear
obj.ActiveSheet.Range("A2")=iMonth
obj.ActiveSheet.Range("A3")=iDay
obj.ActiveSheet.Range("A4")=iHour
obj.ActiveSheet.Range("C2")=bPagePrint
obj.ActiveSheet.Range("C1")=strPrinterName
obj.application.run "DB2Excel"
sleep(100)
obj.application.run "Excel2Table"
sleep(100)
obj.application.run "Table2File"
obj.ActiveWorkbook.Close savechanges:=true 'true ???
obj.quit
PointSet "master.i0[10]",0
PointSet "master.i0[11]",0
'///////////////////////////////////////////////////////////
For i=0 To 63 Step 1
tReal = PointGet("MASTER.REP0[" &i &"]")
PointSet "VIR.HR_REP0[" &i &"]",tReal
tReal = PointGet("MASTER.REP1[" &i &"]")
PointSet "VIR.HR_REP1[" &i &"]",tReal
tReal = PointGet("MASTER.REP2[" &i &"]")
PointSet "VIR.HR_REP2[" &i &"]",tReal
'tReal = PointGet("MASTER.REP3[" &i &"]")
'PointSet "VIR.HR_REP3[" &i &"]",tReal
Next
'//////////////////////////////////////////////////////////
End Sub
Sub CheckFileIsOpen()
Dim xl As Object
On Error Resume Next
Set xl = GetObject(, "Excel.Application")
xl.Workbooks("Hr_Rep.xlsm").Activate
If Err.Number = 0 Then
Exit Sub
End If
If Err.Number <> 0 Then
xl.workbooks("Hr_Rep.xlsm").Close savechanges:=true
End If
End Sub
Any help would be greatly appreciated...