View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
blackhawk blackhawk is offline
external usenet poster
 
Posts: 3
Default On Error doesn't trap Application.Run error

Patrick,

Thanks for the reply. Ok, I am losing my mind....I can put the same macro
you have in a new workbook and it works fine (the error gets trapped). As
soon as I try to place it into my module within the add-in, it does not work.

My hair is getting thinner by the moment......Any suggestions?

"Patrick Molloy" wrote:

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????