View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Error Handling Problem calling Macro from Other Worksheet

You could comment out the open statement and start with the 2nd workbook
already opened. Then you can set break point in the 2nd worksheet and be
abble to debug the problem.

"Marcelo Chou" wrote:

On Sep 3, 10:54 pm, Dave Peterson wrote:
Application.Run is looking for a string.

Maybe:

Application.Run file_name & "!Macro1"

or in case your file_name needs to be surrounded by apostrophes
(and this won't hurt if the file_name doesn't need them):

Application.Run "'" & file_name & "'!Macro1"



Marcelo Chou wrote:

Hi,
got a problem trying to catch a error when i'm calling a macro from
another workbook using the
Application.Run statement. My code is like this:


Public Sub OpenFileMacro(file_name)


On Error Goto Error
Worbooks.open file_path & file_name ' Open the file
Workbooks("file_name").Activate 'focus to the worksheet
Sheets("sheet_name").Select 'select the target
sheet for the macro
Application.Run (file_name!Macro1) 'Run macro1 from the
worksheet.


Error:
ActiveCell.Offset(0, 1).Value = "Can't Open file or Macro is failing"
'message to write in a cell
For Each oWkBook In Workbooks ' close wb if is
open
If UCase(oWkBook.FullName) = UCase(file_name) Then
Workbooks(file_name).Close savechanges:=False
Exit For
End If
Next
exit sub
End Sub


The code runs from a macro in another workbook with the filenames.
I want to determine which files can run the macro and which can't
writing in a cell in the wb with the filenames.


Can anybody help me?


--

Dave Peterson


Well, i put the apostrophes but it doesn't help. Thanks anyway.
I think is something with the Application.Run statement running in the
other workbook, so that the error belongs to THAT workbook. Problem is
there are too many files to open, and the wb is password protected.
VBA error handling is a pain in the back and i don't have .net for a
try/catch.