JnLlnd
JnLlnd

Reputation: 195

Calling macro with Application.Run gives an error 1004

I can't find the cause of the error 1004 returned by the Application.Run command.

Sub Called()
  MsgBox "Yes"
End Sub

Sub Caller()
  Call Called ' works
  subName = "Called"
  Application.Run Application.ActiveWorkbook.Name & "!" & subName ' error 1004
End Sub

Error description (in French):

---------------------------
Erreur d'exécution '1004':
Erreur définie par l'application ou par l'objet
---------------------------

Every solution I found after googling this issue leads to the same error. The Caller and Called subs are in the same "Sheet1" module.

I'm a bit lost. I wonder if the issue is related to XL security? Or something missing in References?

Upvotes: 1

Views: 3711

Answers (3)

S1000RR
S1000RR

Reputation: 1

Remark: I had the Problem with Error 1004 "sub or function not found" error after Application.Run macro, arg

But macro without arg worked.

I found that in the target Workbook the way of declaration of the parameter arg caused a difference:

macro(arg$) -> caused error

macro(arg As String) -> worked (for a moment)

Later same errors again ... Very strange behaviour of Excel VBA Editor: In the line with the Application.Run command VBE had a offset of 2 characters from the cursor, which means when I set the cursor after the n of Run and pressed backspace the R of Run was deleted. Same offset when I typed characters. That issue was moving when I copy-paste that line.

I found out that the errors occured in the lines which had that issue.

I solved it by typing the line new (regarding that the new line didn't have that issue) and deleting the old line, which had that issue.

Upvotes: 0

Mike Benstead
Mike Benstead

Reputation: 61

I had the same problem.

I fixed it by moving the second macro to the same module.

Looks like a memory issue.

Upvotes: 1

YowE3K
YowE3K

Reputation: 23974

Move your code out of the Sheet1 module and into a normal module.

Upvotes: 4

Related Questions