You are here: More... > Use macros to run a script

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.

    Note: The code below is for the 32-bit version of Studio for Salesforce. If you are using the 64-bit version, change the path at the beginning.

  5. Replace the data file path, script file path, sheet name, and autologon name below with the information for your files and Autologon 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.

Code

Private const WSProductPath As String = "C:\Program Files (x86)\Winshuttle\Studio for Salesforce\Winshuttle.Salesforce.Console.exe"
 
' Upload data to Winshuttle For Salesforce
 
Sub RunScript()
    Dim strFilename As String, strSheetname As String
    Dim strWsScriptName As String
    Dim strAutologonName  As String
 ' Excel file name to Run/Upload+
e4w44trFilename = "c:\users\[WindowsUser]\documents\Winshuttle\Studio\Data\Create_Account.xlsm"
 
    ' Excel sheet name to Run/Upload
    strSheetname = "SalesAccounts"
 
    ' Winshuttle for Salesforce Script
    strWsScriptName = "c:\users\[WindowsUser]\documents\Winshuttle\Studio\Script\Create_Account.stx"
   
   
    ' Autologon name can be copied from the Autologon tab from the Desktop product.
    strAutologonName = "Dev_Acc1"
   
    Dim cmdLineArguments As String
     cmdLineArguments = " -run" & strWsScriptName & _
        " -aln" & strAutologonName & _
        " -rfn" & strFilename & " -drf" & " -drs" & strSheetname
   
   ' Run using winshuttle console runner 
    Shell WSProductPath & " " & cmdLineArguments, vbMaximizedFocus
   
End Sub
 
' Upload data of Specific Rows using Winshuttle For Salesforce
 
Sub RunScript_SpecificRows()
    Dim strFilename As String, strSheetname As String
    Dim strWsScriptName As String
    Dim strAutologonName  As String
    Dim StartRow As Long, EndRow As Long
   
    ' Excel file name to Run/Upload
    strFilename = "c:\users\[WindowsUser]\documents\Winshuttle\Studio\Data\Create_Acct.xlsm"
   
    ' Excel sheet name to Run/Upload
    strSheetname = "SalesAccounts"
   
    ' Winshuttle for Salesforce Script
    strWsScriptName = "c:\users\[WindowsUser]\documents\Winshuttle\Studio\Script\Create_Account.stx"
   
    ' Specify Start and End Rows
    StartRow = 2
    EndRow = 500
   
    ' Autologon name can be copied from the Autologon Tab in the Desktop product.
    strAutologonName = "Dev_Acc1"
   
    Dim cmdLineArguments As String
    cmdLineArguments = " -run" & strWsScriptName & _
        " -aln" & strAutologonName & _
        " -drf" & _
        " -rfn" & strFilename & " -drs" & strSheetname & _
        " -dsr" & StartRow & " -der" & EndRow
   
   ' Run using winshuttle console runner 
    Shell WSProductPath & " " & cmdLineArguments, vbMaximizedFocus
   
End Sub