0

I am running the macros using VB scripts from Excel file using below code

Set xl = CreateObject("Excel.Application")
'Set xl.Visible = False 
 'Set xl.DisplayAlerts = False 
 Set wb = xl.Workbooks.Open("E:\Excel\TempDir\NewFile1.xls",,TRUE)
 xl.Application. 
 xl.Application.Run "'E:\Excel\TempDir\NewFile1.xls'!GetId"
 xl.Application.Run "'E:\Excel\TempDir\NewFile.xls'!GetType"
 xl.Application.Run "'E:\Excel\TempDir\NewFile.xls'!GetArea"
 xl.Application.Run "'E:\Excel\TempDir\NewFile.xls'!GetInt"
 xl.Application.Run "'E:\Excel\TempDir\NewFile.xls'!GetSubArea"
 xl.Application.Run "'E:\Excel\TempDir\NewFile.xls'!PickParent"
 xl.Application.Run "'E:\Excel\TempDir\NewFile.xls'!GenerateIds"
 xl.Application.Run "'E:\Excel\TempDir\NewFile.xls'!Load"
 xl.Application.Run "'E:\Excel\TempDir\NewFile.xls'!RefToLibrary" 
 xl.DisplayAlerts = False
  xl.Application.Quit 
 Set xl=Nothing

Using vb script I am able to run multiple macros, but how to skip particular macro if it is not present in Excel file dynamically.

Thank You in advance.

A.Raut
  • 13
  • 3
  • Surround each `xl.Application.Run` with an `If Err.Number <> 0 Then` to check if an error was thrown, don't forget the `On Error Resume Next`. See the linked duplicate. – user692942 Jul 21 '20 at 09:44
  • 1
    Thank you, it is working for me – A.Raut Jul 21 '20 at 09:55

0 Answers0