Hey there. I am not a Visual Basic programmer, but know my way around
some code that I inherited. The following is some code that runs a data
transfer from Excel to SAS. It works on my machine but not on another
one that I'm trying to run it on. I always get the SAS Not Running error
even when it is. The crash is at the AppActivate, line=23. Apparently
Windows doesn't recognize the title in the title bar of a non microsoft
application. How can I get it to recognize SAS?
Option Explicit
1 Sub submit_program(ByVal pgm As String)
2 ' Activates SAS and submits the code stored in pgm
3
4 If SwitchToSAS() = False Then Exit Sub
5
6 ' move cursor to command box, clear log & pgm windows, submit code
7 SendKeys String:="%gtc", Wait:=True
8 SendKeys String:="clear log; pgm; clear; inc '" & pgm & "';
submit;~", Wait:=True
9
10 End Sub
11
12
13 Sub usage()
14 ThisWorkbook.DialogSheets("Usage Dialog").Show
15 End Sub
16
17
18 Function SwitchToSAS() As Boolean
19 ' Activates SAS and maximizes the SAS window. Returns TRUE if
successful.
20
21 On Error GoTo SASNotRunning
22
23 AppActivate Title:="SAS"
24 SendKeys String:="% ", Wait:=True
25 SendKeys String:="x", Wait:=True
26 SwitchToSAS = True
27 Exit Function
28
29 SASNotRunning:
30 ' You probably got here because SAS is not running, so just report
the error
31 ' and return False.
32 MsgBox "ERROR: SAS is not running."
33 SwitchToSAS = False
34
35 End Function
etc...
If I comment out line 21 and 29-33 then the code bombs at line 23,
AppActivate title:"SAS".
runtime error '5'
Invalid procedure call
AppActivate Title:="SAS"