"Application.Run" Problem

TFCJamieFay

Active Member
Joined
Oct 3, 2007
Messages
480
Hi Guys,

I'm trying to call a sub called "ValidateApp", stored in a module called "ValidateApp" with the following code...

Code:
Private Sub SubmitBtn_Click()

    msg = MsgBox("Are you sure you want to submit this application?", vbYesNo + vbExclamation, _
        "Warning!")
    
    If msg = vbNo Then
        TrackerForm.MainNameTBx.SetFocus
    Else
        Application.Run "ValidateApp"
    End If

End Sub

...the problem is however that I get an error on the line...

Code:
Application.Run "ValidateApp"

...saying that the macro cannot be found. The "Private Sub SubmitBtn_Click" is ran from a user form with a command button.

I have recently moved the code to a new module, which is probably the cause but what can I change so it now knows where to look? If it's any help the old module was called "SecondaryCode".

Many thanks,

Jay
 
Whilst you can, as Kenneth said, use the same name for the module and routine (and workbook!), it is not, IMO, good practice. Nor is calling a sub "Run" for that matter! :)
Also, as Mark said, there is no need for using Application.Run anyway if the code is in the same workbook, unless you made it private for some reason. However, if you did want to use it, then you can use:
Code:
Application.Run "'" & Thisworkbook.name & "'!macro_name"
Note that if you need to pass an object to this macro, you can't do that with Run, but you can if you call it directly.
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top