Written by: STATISTICA 11/12/2009 4:14 PM
Note: Words that are highlighted in bold, blue are object names in STATISTICA Visual Basic.
When you record a STATISTICA macro, the active dataset is used for analysis. You will see these lines in the macro.
Dim S1 As Spreadsheet Set S1 = ActiveDataSet
Another option is to access the dataset by file name.
Dim newanalysis As Analysis Set newanalysis = Analysis (scBasicStatistics, Path & "\Examples\Datasets\Adstudy.sta")
But what if your STATISTICA macro is saved in a workbook with the active dataset? How can you reference this spreadsheet?
If the Workbook is visible and on top, you could use ActiveDataSet or ActiveWorkbook.ActiveInput.
You can also use This.Macro which was added to STATISTICA 8.0.669.0. This.Macro returns a pointer to the Macro document of the running macro.
Here is a code snippet that first finds the Macro document that represents the running macro. Next the code checks to see if the macro is within a workbook. The macro then uses the active dataset within the workbook.
Dim oM As Macro Dim oS As Spreadsheet
' return the Macro document of the running macro Set oM = This.Macro
If (Not oM.WorkbookItem Is Nothing) Then
Dim oWB As Workbook
'Get containing Workbook from the WorkbokItem Set oWB = oM.WorkbookItem.Workbook'
If (Not oWB.ActiveInput Is Nothing) Then
' Note you will need to Unlock this Set oS = oWB.ActiveInput.Object
End If
... use oS as data source
' when done, unlock the item if (Not oS.WorkbookItem Is Nothing) oS.WorkbookItem.Lock = False
0 comment(s) so far...