title: Task Schedule Open Excel file, Refresh Bloomberg Data, then Save and Close File
body: <p>I have tried to collect all codes I could have done and it still not work for me.
  What I want to do is to Schedule Task of my Excel file and I have code &quot;RunExcel.vbs&quot; as attached but still not working.</p>
  <p>Reference Link: <a href="https://stackoverflow.com/questions/22771185/how-to-set-recurring-schedule-for-xlsm-file-using-windows-task-scheduler">How to set recurring schedule for xlsm file using Windows Task Scheduler</a></p>
  <p>Reference Link: <a href="https://www.mrexcel.com/forum/excel-questions/794869-vb-script-refresh-bloomberg-feed-excel.html" rel="nofollow noreferrer">https://www.mrexcel.com/forum/excel-questions/794869-vb-script-refresh-bloomberg-feed-excel.html</a></p>
  <ol>
  <li>Open file “PriceRealTIme.xlsm”(Macro-enabled workbook) which is inside “TEst folder”.</li>
  <li>Ignore to update link</li>
  <li>Let it “Refresh Bloomberg Data” and “wait for at 1 minutes or until it done refreshing”.</li>
  <li>Once it’s done. I want to copy paste Value of those columns by using Macro named “CopyPaste”.</li>
  <li>Finally, let it “Save” and  “Close” file.</li>
  </ol>
  <blockquote>
  <pre><code>  '   a .vbs file is just a text file containing visual basic code that has the extension renamed from .txt  to .vbs
  
  'Write Excel.xls  Sheet's full path here
  strPath = &quot;C:\Users\chaic\OneDrive\Desktop\TEst\PriceRealTIme.xlsm&quot; 
  
  'Write the macro name - could try including module name
  strMacro = &quot;Sheet1.CopyPaste&quot; 
  
    'Create an Excel instance and set visibility of the instance
  Set objApp = CreateObject(&quot;Excel.Application&quot;) 
  objApp.Visible = True   '   or False 
  
    'Open workbook; Run Bloomberg Addin; Run Macro; Save Workbook with changes; Close; Quit Excel
  Set wbToRun = objApp.Workbooks.Open(strPath) 
  
  Private Const BRG_ADDIN As String = &quot;BloombergUI.xla&quot;
  Private Const BRG_REFRESH As String = &quot;!RefreshAllStaticData&quot;
  Private TimePassed As Integer
  
  Sub StartAutomation()
      Dim oAddin As Workbook
      On Error Resume Next
      Set oAddin = Workbooks(BRG_ADDIN)
      On Error GoTo 0
      If Not oAddin Is Nothing Then
          Application.Run BRG_ADDIN &amp; BRG_REFRESH
          StartTimer
      End If
  End Sub
  
  Private Sub StartTimer()
      TimePassed = 10
      WaitTillUpdateComplete
  End Sub
  
  Sub WaitTillUpdateComplete()
  
      If WorksheetFunction.CountIf(ThisWorkbook.Names(&quot;BloombergDataRange&quot;).RefersToRange,&quot;#VALUE!&quot;) = 0 Then
          Application.StatusBar = &quot;Data update used &quot; &amp; TimePassed &amp; &quot;seconds, automation started at &quot; &amp; Now
      Else
          Application.StatusBar = &quot;Waiting for Bloomberg Data to finish updating (&quot; &amp; TimePassed &amp; &quot; seconds)...&quot;
          TimePassed = TimePassed + 1
          Application.OnTime Now + TimeSerial(0, 0, 1), &quot;WaitTillUpdateComplete&quot;
      End If
  
  End Sub
  
  objApp.Run strMacro     '   wbToRun.Name &amp; &quot;!&quot; &amp; strMacro 
  wbToRun.Save 
  wbToRun.Close 
  objApp.Quit 
  
     'Leaves an onscreen message!
  MsgBox strPath &amp; &quot; &quot; &amp; strMacro &amp; &quot; macro and .vbs successfully completed!&quot;,         vbInformation
  </code></pre>
  </blockquote>