BookmarkSubscribeRSS Feed
undurip
Calcite | Level 5

Hello Everybody,

 

I am trying to use VBScript to run one of my SAS EG Projects. 

 

I have both .vbs program and the .egp project in my computer, but SAS EG (7.13) is installed in a Virtual Machine (VMware Horizon), so I don't know how to create an object to set the app.

 

The .vbs file contains the following code:

 

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\test.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

When I try to run this .vbs program, it throws the following error:

Error #1AD

In Function CreateObject

ActiveX component can't create object

Is there any possibility of running a SAS Enterprise Guide using VBScript in a SAS installed on a Virtual Machine?

 

Thanks in advance.

 

3 REPLIES 3
Kurt_Bremser
Super User

You need to have Enterprise Guide installed and properly configured in the place where the VB script runs. In your case, that means that the script must run in the VM, and the project file be accessible from within the VM.

undurip
Calcite | Level 5

First of all, thank you so much for your response.

 

Being honest I expected that answer. However, what is confusing me is that I can just double click in my .epg project (stored in my computer) and it automatically opens in the virtualized SAS EG. How is it possible that I can launch this virtualized SAS EG directly from my computer, but I can't run it from a .vbs also on my computer?

 

Thanks again for the help!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2445 views
  • 0 likes
  • 2 in conversation