title: Run Excel Macro from external VBScript Error
body: <p>I have two files. </p>
  
  <ol>
  <li>example.wsf: an automation script </li>
  <li>example.xlsm: an excel template with Macro, the Macro contains a API call to external server to retrieve data.</li>
  </ol>
  
  <p>I am trying to call the Macro inside the example.wsf. </p>
  
  <p>The example.wsf code:</p>
  
  <pre><code>&lt;package&gt;
  
    &lt;job id="example"&gt;
      &lt;script language="vbscript"&gt;
  
          Set objApp = CreateObject("Excel.Application")
  
          Set objExcel = objApp.Workbooks.Open("example.xlsm",0,FALSE)    
          objApp.Visible = True
          objApp.DisplayAlerts = False
  
          objApp.Run("RefreshData")   
  
          msgbox "closing"
  
          objExcel.Close
          objApp.Quit
  
          Set objExcel = Nothing
          Set objApp = Nothing
  
          set objShell = Nothing
  
      &lt;/script&gt;
    &lt;/job&gt;
  
  &lt;/package&gt;
  </code></pre>
  
  <p>The Excel Macro code in example.xlsm:</p>
  
  <pre><code>Public Sub RefreshData()
    Dim API As New EXTERNAL_API
    Dim varResult As Variant
    Dim vSheet As String
    Dim LastRow, LastCol, vResult
    vSheet = "D"
  
    ActiveWorkbook.Sheets(vSheet).Select
    Range("A6").Select
    Selection.Copy
    Range(Selection, Selection.End(xlDown)).Select
    LastRow = ActiveWorkbook.Sheets(vSheet).Cells(8, 1).End(xlDown).Row
    LastCol = 18
  
    API.ActivateAPI
    varResult = API.RunApplication("OfficeAPI", "application=excel,method=RefreshAll")
    MsgBox (varResult)
  
  End Sub
  </code></pre>
  
  <p>The Macro itself is working well if it is triggered inside the Excel workbook. </p>
  
  <p>But when the Macro is called from the VBScript, the EXTERNAL_API fail to execute, i.e., the following line does not execute:</p>
  
  <pre><code>varResult = API.RunApplication("OfficeAPI", "application=excel,method=RefreshAll")
  </code></pre>
  
  <p>I am suspecting that this may be related to early binding but basically have no clue what went wrong.</p>