View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default On Error doesn't trap Application.Run error

This worked for me

Sub tester()
Dim wb As Workbook

On Error GoTo finish

Set wb = Workbooks.Open("S:\staff\patrick\excel stuff\welcome.xls")
Application.Run "Welcome.xls!Welcome"
wb.Close False

finish:
On Error GoTo 0

End Sub

Patrick Molloy
Microsoft Excel MVP



"blackhawk" wrote:

I have a macro in an XLA that is trying to run a macro in a different
workbook, if the macro does not exist, I just want to ignore it and continue,
otherwise run it.

It works fine if the macro exists, but if it doesn't I get the runtime 1004
error dialog box, and no matter what I do, I cannot seem to prevent it.
Here is a sample of my code:

Public Sub RunMacro( FileName )
On Error GoTo Finish
Set ReportWorkbook = Workbooks.Open(FileName, , True)
Application.Run ReportWorkbook.Name & "!Execute"
On Error GoTo 0
Finish:
End Sub

Am I missing something here????