Quote Originally Posted by Kenneth Hobs
VBA's Environ() will not update when reset for that session using an API method to reset it. I used API methods to set and get environment variables which worked fine. One of the four methods that I tried using WScript acted the same as Environ(). The other three worked just as well as the API method.

Not sure which SAS envrionment variable you would have that could tell you what you need. I used to use SAS on the mainframe. A friend uses PCSAS which I could check if needed.

You can check the environment variables manually or add a command button to a sheet and add this code to view with a button click. Put the first part in a Module and the Sub as the button's click event.

[vba] Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Sub CommandButton2_Click()
Dim rc As Long
'Shell "cmd /c RunDll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,3", vbNormalFocus
Shell "Control.exe sysdm.cpl,,3", vbNormalFocus
Do Until FindWindow(vbNullString, "System Properties") <> 0
Loop
Application.SendKeys "n", True
End Sub
[/vba]
Kenneth, thanks for your contribution. I have tried running your code and have the following screenshot of the outcome.

I wasn't sure how to use this exactly though. Could you please clarify (my understanding of API's is extremely novice in relation to yours ).?


I am not sure how you are starting Excel from SAS. You could use the registry to poke and peek for what you need. VBA's GetSetting() and SaveSetting() can be used for that.
I am not actually starting Excel from SAS the application, rather trying to batch run SAS Programs from an Excel workbook. Using Excel as a front end allows for more clarity and controlling in opening and batching SAS programs as required.

Given that SAS programs (macros) can only be run from teh SAS Server, I need a simple UDF to check that the Excel Application is open from the SAS Server, not the local Server.

I have clarified tis more in my reply to Bob, in my previous post.

Please let me know if you need me to specify further information.

The UDF designed in earlier posts seems to be working, but based on the issues raised about the static nature of these Environ variables, I would be keen to develop and understand and API UDF approach.

Sincere thanks and regards for your interest in this problem.