BookmarkSubscribeRSS Feed
learner_sas
Quartz | Level 8

Hello Everybody,

I am trying to schedule one of my SAS EG project. For this process this is the step I followed

1) open my project

2) right click on process flow and select schedule process flow

3) and update required parameters and save the file

4) EGScript1.vbs is saved in same location.

Now I went to Command prompt and change directory to the directory with .vbs flie and

ran EGScript1.vbs using

CSCRIPT EGScript1.vbs  but vbs file came up with error "Object required as run time error". I am new in

vbs scripting and below is my .vbs code generate while I create schedule process in SAS EG.

Below is my .vbs program;

Option Explicit

Dim app         ' As SASEGuide.Application

Call dowork

'shut down the app

If not (app Is Nothing) Then

    app.Quit

    Set app = Nothing

End If

Sub dowork()

    On Error Resume Next

    '----

    ' Start up Enterprise Guide using the project name

    '----

    Dim prjName     ' As String

    Dim prjObject   ' As SASEGuide.Project

    Dim containerName     ' As String

    Dim containerObject   ' As SASEGuide.Container

    Dim containerColl     ' As SASEGuide.ContainerCollection

    prjName = "C:\Users\usr\Desktop\WFH\SAS_Batch\TestCodeProject.egp" ' Project Name

    containerName = "Process Flow" ' Container Name

     

    Set app = CreateObject("SASEGObjectModel.Application.5.1")

    If Checkerror("CreateObject") = True Then

        Exit Sub

    End If

   

    Set prjObject = app.Open(prjName,"")

    If Checkerror("App.Open") = True Then

        Exit Sub

    End If

   

       

    '-----

    'Get The Container Collection and Object

    '-----   

    Set containerColl = prjObject.ContainerCollection

    If Checkerror("Project.ContainerCollection") = True Then

        Exit Sub

    End If

   

    Dim i       ' As Long

    Dim count   ' As Long

    count = containerColl.count

    For i = 0 To count - 1

        Set containerObject = containerColl.Item(i)

        If Checkerror("ContainerCollection.Item") = True Then

            Exit Sub

        End If

       

        If (containerObject.Name = containerName) Then

            Exit For

        Else

            Set containerObject = Nothing

        End If

    Next

   

    If not (containerObject Is Nothing) Then

        '----

        ' Run the Container

        '----

        containerObject.Run

        If Checkerror("Container.Run") = True Then

            Exit Sub

        End If              

    End If

               

    '-----

    ' Save the new project

    '-----

    prjObject.Save

    If Checkerror("Project.Save") = True Then

        Exit Sub

    End If

   

    '-----

    ' Close the project

    '-----

    prjObject.Close

    If Checkerror("Project.Close") = True Then

        Exit Sub

    End If

      

End Sub

Function Checkerror(fnName)

    Checkerror = False

   

    Dim strmsg      ' As String

    Dim errNum      ' As Long

   

    If Err.Number <> 0 Then

        strmsg = "Error #" & Hex(Err.Number) & vbCrLf & "In Function " & fnName & vbCrLf & Err.Description

        'MsgBox strmsg  'Uncomment this line if you want to be notified via MessageBox of Errors in the script.

        Checkerror = True

    End If

        

End Function

2 REPLIES 2
ChrisHemedinger
Community Manager

It's possible that you need to run the 32-bit version of CSCRIPT:

%windir%\syswow64\cscript.exe

Try this basic test here:

http://blogs.sas.com/content/sasdummy/2011/05/03/using-sas-enterprise-guide-to-run-programs-in-batch...

See some more information here:

http://blogs.sas.com/content/sasdummy/2012/04/17/doing-more-with-sas-enterprise-guide-automation/

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
learner_sas
Quartz | Level 8

Hello Chris,

I was able to run program for using C:\Windows\System32\CScript.exe  ~dir\testone.vbs and following is my code.I am assuming that program ran correctly since I did not see any error message. Is there a way to update program so that I can sent log to my local drives to my record.

Option Explicit

Dim app         ' As SASEGuide.Application

Call dowork

'shut down the app

If not (app Is Nothing) Then

    app.Quit

    Set app = Nothing

End If

Sub dowork()

    On Error Resume Next

    '----

    ' Start up Enterprise Guide using the project name

    '----

    Dim prjName     ' As String

    Dim prjObject   ' As SASEGuide.Project

    Dim containerName     ' As String

    Dim containerObject   ' As SASEGuide.Container

    Dim containerColl     ' As SASEGuide.ContainerCollection

    prjName = "C:\Users\xxx\Desktop\WFH\SAS_Batch\TestCodeProject.egp" ' Project Name

    containerName = "Process Flow" ' Container Name

     

    Set app = CreateObject("SASEGObjectModel.Application.5.1")

    If Checkerror("CreateObject") = True Then

        Exit Sub

    End If

   

    Set prjObject = app.Open(prjName,"")

    If Checkerror("App.Open") = True Then

        Exit Sub

    End If

   

       

    '-----

    'Get The Container Collection and Object

    '-----   

    Set containerColl = prjObject.ContainerCollection

    If Checkerror("Project.ContainerCollection") = True Then

        Exit Sub

    End If

   

    Dim i       ' As Long

    Dim count   ' As Long

    count = containerColl.count

    For i = 0 To count - 1

        Set containerObject = containerColl.Item(i)

        If Checkerror("ContainerCollection.Item") = True Then

            Exit Sub

        End If

       

        If (containerObject.Name = containerName) Then

            Exit For

        Else

            Set containerObject = Nothing

        End If

    Next

   

    If not (containerObject Is Nothing) Then

        '----

        ' Run the Container

        '----

        containerObject.Run

        If Checkerror("Container.Run") = True Then

            Exit Sub

        End If              

    End If

               

    '-----

    ' Save the new project

    '-----

    prjObject.Save

    If Checkerror("Project.Save") = True Then

        Exit Sub

    End If

   

    '-----

    ' Close the project

    '-----

    prjObject.Close

    If Checkerror("Project.Close") = True Then

        Exit Sub

    End If

      

End Sub

Function Checkerror(fnName)

    Checkerror = False

   

    Dim strmsg      ' As String

    Dim errNum      ' As Long

   

    If Err.Number <> 0 Then

        strmsg = "Error #" & Hex(Err.Number) & vbCrLf & "In Function " & fnName & vbCrLf & Err.Description

        'MsgBox strmsg  'Uncomment this line if you want to be notified via MessageBox of Errors in the script.

        Checkerror = True

    End If

        

End Function

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 11207 views
  • 0 likes
  • 2 in conversation