0

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.

Miles Fett
  • 711
  • 4
  • 17
Navid
  • 1
  • 3
  • 3
    Possible duplicate of [Run Excel Macro from Outside Excel Using VBScript From Command Line](https://stackoverflow.com/questions/10232150/run-excel-macro-from-outside-excel-using-vbscript-from-command-line) – tripleee Sep 10 '19 at 09:29
  • Hi Miles, thanks for that. But is does not solve my issue. – Navid Sep 11 '19 at 19:16

0 Answers0