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 "RunExcel.vbs" as attached but still not working.
Reference Link: How to set recurring schedule for xlsm file using Windows Task Scheduler
Reference Link: https://www.mrexcel.com/forum/excel-questions/794869-vb-script-refresh-bloomberg-feed-excel.html
- Open file “PriceRealTIme.xlsm”(Macro-enabled workbook) which is inside “TEst folder”.
- Ignore to update link
- Let it “Refresh Bloomberg Data” and “wait for at 1 minutes or until it done refreshing”.
- Once it’s done. I want to copy paste Value of those columns by using Macro named “CopyPaste”.
- Finally, let it “Save” and “Close” file.
' 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 = "C:\Users\chaic\OneDrive\Desktop\TEst\PriceRealTIme.xlsm" 'Write the macro name - could try including module name strMacro = "Sheet1.CopyPaste" 'Create an Excel instance and set visibility of the instance Set objApp = CreateObject("Excel.Application") 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 = "BloombergUI.xla" Private Const BRG_REFRESH As String = "!RefreshAllStaticData" 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 & BRG_REFRESH StartTimer End If End Sub Private Sub StartTimer() TimePassed = 10 WaitTillUpdateComplete End Sub Sub WaitTillUpdateComplete() If WorksheetFunction.CountIf(ThisWorkbook.Names("BloombergDataRange").RefersToRange,"#VALUE!") = 0 Then Application.StatusBar = "Data update used " & TimePassed & "seconds, automation started at " & Now Else Application.StatusBar = "Waiting for Bloomberg Data to finish updating (" & TimePassed & " seconds)..." TimePassed = TimePassed + 1 Application.OnTime Now + TimeSerial(0, 0, 1), "WaitTillUpdateComplete" End If End Sub objApp.Run strMacro ' wbToRun.Name & "!" & strMacro wbToRun.Save wbToRun.Close objApp.Quit 'Leaves an onscreen message! MsgBox strPath & " " & strMacro & " macro and .vbs successfully completed!", vbInformation