How to create a batch file that will run a Statistica macro automatically?

How to create a batch file that will run a Statistica macro automatically?

book

Article ID: KB0074314

calendar_today

Updated On:

Products Versions
Spotfire Statistica 12.0 and higher

Description

Automating running a macro with the help of a batch file. 

Issue/Introduction

How to create a batch file that will run a Statistica macro automatically ?

Environment

Windows operating systems.

Resolution

In the following example, a batch file will be created which runs a macro.  The macro will create a spreadsheet object, open, and save the spreadsheet to the desktop location.  An additional steps will be setup to have Windows run this periodically.

CREATE AND NAME THE MACRO
1   Using the Ribbon Bar, select the 'Home' tab.

2.  In the File section, select New | Macro.

3.  Add the following SVB code in the Main procedure:
 Dim ss As Spreadsheet
 Set ss = Spreadsheets.Open(Path & "\Examples\Datasets\Poverty.sta",False)
 ss.SaveAs("c:\users\username\desktop\output.sta", True)
Macro

4.  In the File section select Save | Save As and name the macro. 

Note:  Other examples can be found in the Online Help (for Statistica 12 and later, from the Ribbon Bar, select the File tab, then click Help/Support).

CREATE AND NAME THE BATCH FILE
1.  Open Notepad and enter the following command:
"C:\Program Files\StatSoft\STATISTICA 12\statist.exe" /u "admin" /w "abcdef" /runmacro="C:\users\username\desktop\SaveSheet.svb" /nologo

Batch code
Note:  See Statistica Enterprise Command Line Options (148965) for command line options and explanations. 

2.  Save and name the file adding a .bat file as the extension:
Batch Icon
3.  Double-click the batch file icon to run the batch file

4. The output.sta file be created and saved on the Desktop location:
Output

SETUP WINDOWS TASK SCHEDULER
 
1.  Click Start | Control Panel | Administrative Tools | Task Scheduler

2.  In the Actions section, select 'Create Basic Task...' to begin the wizard.  Enter the name and click 'Next':
Basic Task Wizard

3.  Select when the task is to start and click 'Next':
Trigger

4.  Select the trigger options and click 'Next':
Trigger options

5.  Select 'Start a program' as the Action and click 'Next':
Action

6.  Browse to the batch file and click 'Next':
Select Action

7.  Click 'Finish' to complete the wizard:
Wizard Finish