Use Macros to Run a SAP script - Automate_Studio - Latest

Automate Studio with Evolve User Guide

Product type
Software
Portfolio
Integrate
Product family
Automate
Product
Automate > Automate Studio
Version
Latest
Language
English
Product name
Automate Studio
Title
Automate Studio with Evolve User Guide
Copyright
2024
First publish date
2018
Last updated
2024-07-22
Published on
2024-07-22T13:07:48.665095

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.
    Note: 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.
  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 Evolve).

Asynchronous macro runs are supported.

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.

    Dim StudioMacros.PublishedFile = "Change Material-MM02"

  5. Open the published script.

    StudioMacros.OpenPublishedScript

  6. Run AddinObject to run script.

    StudioMacros.RunScript

Run an existing GUI for HTML 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 GUI for HTML script to run, and define other run properties (see Properties for a GUI for HTML Addin object).

    The following is for running the solution locally: Dim strShuttleFile = "C:\Users\Normal_Tx_Macro.txr" The following is for running the solution from Evolve: StudioMacros.LibraryName = "Transaction" Set to Solution Name for solutions submitted from Evolve. strShuttleFile = "Manage Product Master Data"

  5. Open the script to Run.

    StudioMacros.OpenScript (strShuttleFile)

  6. Run AddinObject to run script.

    StudioMacros.RunScript

Properties for a GUI for HTML Add-in 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

LibraryName NA Opens the library which includes the solution

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

ConnectionName

AlfName

SAP connection name

Example

StudioMacros.ConnectionName = "S23"

Used in case of Evolve and Studio Manager.

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

2 – Run First Five Rows

3 – Run Only Error Rows

4 – Run Only Unprocessed Rows

7 – Validate Specified Range

8 – Validate First Five Rows

9 – Validate Only Error Rows

10 – Validate Only Unprocessed Rows

15 – Run Unprocessed Rows and Error Rows

16 - Validate Unprocessed and Error Rows

Select the type of run from the possible values

 

RunScript

NA

Run the script

SyncCall

NA

True – Run the script in a synchronous fashion

Sample code: Run a published SAP GUI script

 this sample code will be updated with the "Run Error Row and Unprocessed Rows" run type.


 Sub RunPublishedTXRfile()
'----------------------------------------------
' 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


     ' Select the published file to Run

     StudioMacros.PublishedFile = "Change Material-MM02_MacroTest"


     StudioMacros.StartRow = 2

     StudioMacros.EndRow = 6


     ' Set True to write headers while Run

     StudioMacros.WriteHeader = True


 'StudioMacros.LogColumn = "H"

 'StudioMacros.SheetName = "Sheet2"


 'StudioMacros.ConnectionName = "S23"


     ' Set RunReason to provide reason for run.

     StudioMacros.RunReason = "Run Reason"



     'StudioMacros.RunSelectedRows = True

     'StudioMacros.RunFilteredRows = True



     ' RunSpecifiedRange = 0,

     ' RunFirstFiveRows = 2,

     ' RunOnlyErrorRows = 3,

     ' RunOnlyUnProcessedRows = 4,

     ' ValidateSpecifiedRange = 7,

     ' ValidateFirstFiveRows = 8,

     ' ValidateOnlyErrorRows = 9,

     ' ValidateOnlyUnProcessedRows = 10,

     ' RunUnProcessedAndErrorRows=15,

     ' ValidateUnProcessedAndErrorRows=16,

     
      StudioMacros.RunType = 0


     ' Call the Run Function to open published script

     StudioMacros.OpenPublishedScript


     ' Call the Run Function to run script

     StudioMacros.RunScript

     Exit Sub

 ErrHandler:

    MsgBox Err.Description

 End Sub 

 

Sample code: Run an existing SAP GUI 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


 'StudioMacros.LogColumn = "H"

 'StudioMacros.SheetName = "Sheet2"

  'StudioMacros.ConnectionName = "S23"

  ' Set RunReason to provide reason for run.

     StudioMacros.RunReason = "Run Reason"

     'StudioMacros.RunSelectedRows = True

     'StudioMacros.RunFilteredRows = True



     ' RunSpecifiedRange = 0,

     ' RunFirstFiveRows = 2,

     ' RunOnlyErrorRows = 3,

     ' RunOnlyUnProcessedRows = 4,

     ' ValidateSpecifiedRange = 7,

     ' ValidateFirstFiveRows = 8,

     ' ValidateOnlyErrorRows = 9,

     ' ValidateOnlyUnProcessedRows = 10,

     ' RunUnProcessedAndErrorRows=15,

     ' ValidateUnProcessedAndErrorRows=16,





     StudioMacros.RunType = 0

  ' Set in case of evolve subitted file

 StudioMacros.LibraryName = "Transaction"

 ' Set it to Solution Name in case of evolve submitted file

 ' For local File,set strShuttleFile to local file path

     strShuttleFile = "Change Material-MM02"

     '  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. While you are using macros, the Automate Add-ins should not be loaded (you should not be logged on to Evolve/Studio Manager). The Automate Add-ins can be enabled.
  2. Start Row is always 2 unless you specify a different row.
  3. RunSelectedRows and RunFilteredRows are mutually exclusive options. The script will use the one that is set last.
  4. Data files must not use the Data Review workflow to be executed by using macros in Studio Manager mode.
  5. Save to Studio Manager will not work when a macro is used to run the data file in Studio Manager mode.