Good Morning Everyone,
I am trying to create a form in Excel which passes contents of X number of cells (in the POC below I am only utilising a one) as parameters within a SAS Stored Process using the Add-in for Microsoft Office. I don't have any issues performing this task on a single query, however when I change the value in A1 and submit the code again I get the following popup box, because the results of the previous query already appear within cell A10:
Query
Sub InsertStoredProcessWithPrompts()
Dim sas As SASExcelAddIn
Set sas = Application.COMAddIns.Item("SAS.ExcelAddIn").Object
'Delete and entries in the existing log
sas.ClearLog
'Setting Options
sas.options.ResetAll
sas.options.AutoInsertResultsIntoDocument = True
sas.options.PromptForParametersOnRefreshMultiple = False
sas.options.ShowStatusWindow = False
'Specify the Cell Used For Parameter Input
Dim age As Range
Set age = Sheet1.Range("A1")
'Capture The Prompts To Be Used As Parameters Within The Stored Process
Dim prompts As SASPrompts
Set prompts = sas.CreateSASPromptsObject
prompts.Add "AGE", age
Dim stp As SASStoredProcess
Set stp = sas.InsertStoredProcess("/User Folders/scmitchell/My Folder/Test Streams", Sheet1.Range("A10"), prompts)
End Sub
Second Execution Result
As a result I added an If statement to identify whether the object associated with the Stored Process already exists. If it does then create the stored process, if not then modify the parameters of the stored process to include the newly defined value in the AGE prompt.
Query
Sub InsertStoredProcessWithPrompts()
Dim sas As SASExcelAddIn
Set sas = Application.COMAddIns.Item("SAS.ExcelAddIn").Object
If stp Is Nothing Then
'Delete and entries in the existing log
sas.ClearLog
'Setting Options
sas.options.ResetAll
sas.options.AutoInsertResultsIntoDocument = True
sas.options.PromptForParametersOnRefreshMultiple = False
sas.options.ShowStatusWindow = False
'Specify the Cell Used For Parameter Input
Dim age As Range
Set age = Sheet1.Range("A1")
'Capture The Prompts To Be Used As Parameters Within The Stored Process
Dim prompts As SASPrompts
Set prompts = sas.CreateSASPromptsObject
prompts.Add "AGE", age
Dim stp As SASStoredProcess
Set stp = sas.InsertStoredProcess("/User Folders/scmitchell/My Folder/Test Streams", Sheet1.Range("A10"), prompts)
Else
Set stp = stp.Modify("Test Streams")
End If
End Sub
First or Subsequent Execution Result
The following is highlighted as the issue:
Dim stp As SASStoredProcess
There is a possibility that I am headed in entirely the wrong direction, so please feel free to offer alternative solutions, however the above seems reasonably sound thus far. I pulled the 'If object' exists code from a StackOverflow post (VBA check if object is set), but maybe I am making a rudimentary mistake as I rarely use VBA.
Any help would be greatly appreciated.
Regards.
Scott