Calling Private Sub from UserForm code

powerpackinduo

Board Regular
Joined
Jul 28, 2005
Messages
128
I have a macro in a workbook with code in the Open event that opens a workbook: daily.xls

In the daily.xls file there is a UserForm with code.

In the UserForm code there are private subs. (private sub name: Update)

How do I have my initial workbook open the daily.xls file and run the private subs found in the userform code?

I've tried the following in the open event:
Code:
Workbooks.Open "C:\daily.xls"

Application.Run ("'daily.xls'!Update")
and I get the message: The macro ''Daily.xls'!Update' cannot be found.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If I do that then they are not available to the Daily.xls userform when that file is used by itself.

Is there any other way?
 
Upvote 0
They are available to the userform in Module code if you change the sub to Public not Private. Dave
 
Upvote 0
A private sub in userform code is available only to the userform. To run a sub in another workbook the sub must be in module code. A private sub in module code is only available to the module. A public sub in module code is available to the whole wb. Far as I know, the sub has to be public and in module code for it to be ran from another wb. Not sure why you're reluctant to have public subs? Dave
 
Upvote 0
It is pretty much a contradiction in terms to want to keep your routines private but be able to call them from elsewhere...;)
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,792
Members
449,048
Latest member
greyangel23

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