I have a similar problem to: Bloomberg data doesn't populate until Excel VBA macro finishes
I wanted to run my macro ConvertTocsv through a vb script file, to schedule it later. In my files are Bloomberg formulas, so I added Sub Master1 with RefreshAllStatisticData so the Bloomberg values can populate. When I run the macro Master1 from the excel it works fine. However, when I run it from the script file I get a run time error "1004".
Here is the code from the vb script file:
dim objXL
dim objWkb
dim strPath
strPath = "S:\Back Office\Tradar\Daily Report Files_Bloomberg\Custom_Daily_Report_BDP_20190807 with Macro_Template.xlsm"
Set objXL = CreateObject("Excel.Application")
Set objWkb = objXL.Workbooks.Open(strPath)
objXL.Run "'" & objWkb.Name & "'!Master1"
Set objWkb = Nothing
Set objXL = Nothing
Here is the macro:
Sub Master1()
Application.Run "RefreshAllStaticData"
Application.OnTime Now + TimeValue("00:00:15"), "ConvertTocsv"
End Sub
Sub ConvertTocsv()
Dim strfilename As String
strfilename = "S:\Back Office\Tradar\DailyReportBDP\Custom_Daily_Report_BDP_" & Format(Now(), "YYYYMMDD") & ".csv"
ChDir "S:\Back Office\Tradar\DailyReportBDP"
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
("S:\Back Office\Tradar\DailyReportBDP\Custom_Daily_Report_BDP_" & Format(Now(), "YYYYMMDD") & ".csv"), FileFormat:=xlCSV, CreateBackup:=True, Local:=True
Application.DisplayAlerts = True
Information.Show
returnvalue = Shell("notepad.exe " & strfilename, vbNormalFocus)
ActiveWorkbook.Close SaveChanges:=False
End Sub
What is wrong? Help is appreciated.