14.03.2014 Views

Automation Reference - JMP

Automation Reference - JMP

Automation Reference - JMP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Application Object <strong>Reference</strong> for Automating <strong>JMP</strong><br />

Automating <strong>JMP</strong> through Visual Basic<br />

The FitModel and DOE examples show operators that are specific to those areas of <strong>JMP</strong>, and whose platform<br />

operator differs slightly from other platforms.<br />

The sample code for all five example programs assumes the data files reside in the default SAMPLE DATA directory.<br />

If you move your sample data files, you need to change the path information in the VB samples.<br />

If there are differences between this document’s examples of Visual Basic code and that in the sample programs,<br />

preference should be given to the sample program code.<br />

Automating <strong>JMP</strong> From Excel 2007<br />

This example automates <strong>JMP</strong> using a macro within an Excel 2007 worksheet. The macro code is written in Visual<br />

Basic. It starts <strong>JMP</strong> in a visible state when the Excel worksheet is initially opened. The Excel worksheet is then<br />

imported into <strong>JMP</strong> using the ODBC automation interface. Once the worksheet data is in <strong>JMP</strong>, changes to individual<br />

worksheet cells are sent to <strong>JMP</strong> and changed in the <strong>JMP</strong> data table.<br />

The first time a row value in Excel changes, <strong>JMP</strong> generates a Control Chart. Subsequent changes to the excel<br />

worksheet result in changes to the Control Charts. This is because Control Chart output is dynamically linked to the<br />

<strong>JMP</strong> data table, which in this example is dynamically updated by Excel. Every fifth time the Excel worksheet changes,<br />

a method is called in <strong>JMP</strong> to generate a .PNG file for the Control Chart. This allows users without <strong>JMP</strong> to view the<br />

output through a web browser. Finally, when the Excel worksheet closes, <strong>JMP</strong> shuts down through automation.<br />

Begin by opening Microsoft Excel. To create a Visual Basic script for an Excel workbook, select Visual Basic from the<br />

Developer ribbon. The Visual Basic editor opens in a separate window. On the left side of the Visual basic editor, there<br />

is a pane entitled VBA Project. This pane shows the sheets that might have Visual Basic code associated with them, as<br />

well as the workbook itself.<br />

Code written for the workbook usually works for any of the sheets within the workbook.<br />

There are three sections involved in the coding for this example. First, there are some variables that are global in scope<br />

that are declared in the module1.bas file. This allows these variables to be referenced in other code modules. A<br />

module can be inserted into the Visual Basic project by context-clicking on the VBA project icon and selecting<br />

Insert > Module. Type the following code into the module. The code declares instances of a <strong>JMP</strong> application, a <strong>JMP</strong><br />

data table, and a flag to keep track of whether a document is open or not.<br />

Public My<strong>JMP</strong> as <strong>JMP</strong>.Application‘The <strong>JMP</strong> Application Object<br />

Public DT As <strong>JMP</strong>.DataTable‘The <strong>JMP</strong> Data Table object<br />

Public DocOpen as Boolean‘A flag indicating “<strong>JMP</strong> Table Open”<br />

The next segment updates <strong>JMP</strong> when cells in the Excel worksheet change. It is called automatically because Excel<br />

generates the Worksheet_change event whenever a cell is changed, deleted, or added.<br />

The Excel VBA Project Browser shows the sheets that are currently part of the workbook. The code below should be<br />

placed in the sheet that sends data to <strong>JMP</strong>. Double-click on the sheet icon in the VBA Project Window to bring up<br />

the code for that particular sheet.<br />

Private Sub Worksheet_change(ByVal Target as Range)<br />

Dim Col as <strong>JMP</strong>.Column<br />

Page 5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!