Help Center>Studio (Connect)

Use macros to run a script

To run a script by using a macro, create the macro in Visual Basic for Applications (VBA).

  1. Open the data file that is associated with the script that you want to run.

    Important: Be sure that you are using a macro-enabled, or .xlsm, file.

  2. Press Alt+F11.
  3. In the VBA Editor, under Microsoft Excel Objects, double-click the sheet that contains the data you want to run.
  4. Copy and paste the code below into the window.
  5. Replace the data file path, script file path, sheet name, and auto logon name below with the information for your files and your auto logon name.
  6. Click Save and then close the VBA Editor.
  7. In Excel, click the View tab, and then click Macros.
  8. Click the macro that you want to run, and then click Run.

Note: Be sure that the Excel Add-in is not active (that you are not logged on to Connect).

Note: An asynchronous macro run is supported.

Transaction macros

Run a published script

  1. Define Addin objects.

    Dim StudioMacrosAddin, StudioMacros

  2. Get Addin object from Excel.

    Set StudioMacrosAddin = Application.COMAddIns.Item("WinshuttleStudioMacros.AddinModule")

  3. Get COM object from Addin object.

    Set StudioMacros = StudioMacrosAddin.Object.Macros

  4. Select the published file to run, and define other run properties (see Properties for a Transaction Addin object).

    StudioMacros.PublishedFile = "MM02_MacroTest"

  5. Open the published script.

    StudioMacros.OpenPublishedScript

  6. Run AddinObject to run script.

    StudioMacros.RunScript

Run an existing Transaction script

  1. Define Addin objects.

    Dim StudioMacrosAddin, StudioMacros

  2. Get Addin object from Excel.

    Set StudioMacrosAddin = Application.COMAddIns.Item("WinshuttleStudioMacros.AddinModule")

  3. Get COM object from Addin object.

    Set StudioMacros = StudioMacrosAddin.Object.Macros

  4. Select the Transaction script to run, and define other run properties (see Properties for a Transaction Addin object).

    Dim strShuttleFile = "C:\Users\Normal_Tx_Macro.txr"

  5. Open the script to Run.

    StudioMacros.OpenScript (strShuttleFile)

  6. Run AddinObject to run script.

    StudioMacros.RunScript

Properties for a Transaction Addin object

Run settings or Advance Run Options set in the script are not respected during the Macro run. These need to be set via the various properties that have been exposed for the Add in object.

Property/Function Value(s)/Parameter Description

PublishedFile

Published script Description

Selects the published file to run

OpenPublishedScript

NA

Opens the published script

OpenScript()

Script file path

Opens the script to run

StartRow

Row Number

Excel row from which data upload should start

EndRow

Row Number

Last Excel row from which data should be uploaded

WriteHeader

NA

Write headers during the run

LogColumn

Column/Cell

Column or cell where run logs should be written

SheetName

Name of sheet

Sheet name to be used for the run

AlfName

Auto logon file

Name of auto logon to use

RunReason

Run reason string

Specify a reason for this run

RunSelectedRows

NA

True – run only the rows that are selected in Excel

RunFilteredRows

NA

True – run only the displayed rows in Excel

RunType

0 – Run Specified Range

1 - Run And Stop On Errors

2 – Run First Five Rows

3 – Run Only Error Rows

4 – Run Only Unprocessed Rows

5 – Debug Specified Range

6 – Debug First Row Only

7 – Validate Specified Range

8 – Validate First Five Rows

9 – Validate Only Error Rows

10 – Validate Only Unprocessed Rows

11 - Simulate Specified Range

12 - Simulate First Five Rows

13 - Simulate Only Error Rows

14 - Simulate Only Unprocessed Rows

Select the type of run from the possible values

RunScript

NA

Run the script

SyncCall

NA

True – Run the script in synchronous fashion

Sample code: Run an existing Transaction script


  Sub RunNormalTXRfile()
                 
  '----------------------------------------------
  ' Macro to use WinshuttleStudioMacros addin with code
  '----------------------------------------------
  '
  ' RunPublishedfile Macro
  '
       Dim StudioMacrosAddin, StudioMacros
                    
       On Error GoTo ErrHandler
       ' GET ADDIN OBJECT FROM EXCEL
       Set StudioMacrosAddin = Application.COMAddIns.Item("WinshuttleStudioMacros.AddinModule")
                    
       If StudioMacrosAddin Is Nothing Then
          MsgBox "Unable to initialize object of WinshuttleStudioMacros.AddinModule addin"
          Exit Sub
       End If
                   
       ' Get com object from addin object
       Set StudioMacros = StudioMacrosAddin.Object.Macros
       If StudioMacros Is Nothing Then
          MsgBox "Unable to initialize com object of Macros"
          Exit Sub
       End If
                    
       StudioMacros.StartRow = 2
                   
       StudioMacros.EndRow = 0
                  
       ' Set True to write headers while Run
       StudioMacros.WriteHeader = True
                  
       ' Set RunReason to provide reason for run.
       StudioMacros.RunReason = "Run Reason"

       'StudioMacros.RunSelectedRows = True
       'StudioMacros.RunFilteredRows = True
                    
       ' RunSpecifiedRange = 0,
       ' RunAndStopOnErrors = 1,
       ' RunFirstFiveRows = 2,
       ' RunOnlyErrorRows = 3,
       ' RunOnlyUnProcessedRows = 4,
       ' DebugSpecifiedRange = 5,
       ' DebugFirstRowOnly = 6,
       ' ValidateSpecifiedRange = 7,
       ' ValidateFirstFiveRows = 8,
       ' ValidateOnlyErrorRows = 9,
       ' ValidateOnlyUnProcessedRows = 10,
                   
       StudioMacros.RunType = 0
                    
       strShuttleFile = "C:\Users\ssingh\Documents\Winshuttle\Studio\Script\Normal_Tx_Macro.txr"
                   
       ' Call the Run Function to open specified script
       StudioMacros.OpenScript (strShuttleFile)

       ' Call the Run Function to run script
       StudioMacros.RunScript
       Exit Sub
                   
  ErrHandler:
       MsgBox Err.Description
  End Sub

Known issues

  1. Macros that were created in Transaction or Query 10.x are not automatically converted to the Studio 12.x format. Macros in Studio 12.x format are not compatible with 10.x. To run, the macros must be manually converted.
  2. While you are using macros, the Winshuttle Add-ins should not be loaded (you should not be logged on to Connect). The Winshuttle Add-ins can be enabled.
  3. Start Row is always 2 unless you specify a different row.
  4. RunSelectedRows and RunFilteredRows are mutually exclusive options. The script will use the one that is set last.