ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Attempting to call a sub from another wb using a Userform option b (https://www.excelbanter.com/excel-programming/436820-attempting-call-sub-another-wb-using-userform-option-b.html)

OffDev

Attempting to call a sub from another wb using a Userform option b
 
Please assist.

I have an userform that has several options button each calls a sub proc
from another workbook
I am getting run-time error 1004 Method Run of object_Application failed
when I click on the button when the other workbook close .

When the workbook is open I am getting run-time error 1004 Cannot run the
macro wbMain.xlsm!cmdOpenfile. The macro may not be available in this
workbook or all macros may be disabled.but with a different reason.
My macros options are enabled and has trusted access.

I am baffled because the code is very simple:

Application.run "wbMain!subproc"

Thanks
Offdev

OssieMac

Attempting to call a sub from another wb using a Userform option b
 
Am I guessing correctly that wbMain is a workbook variable?

If so then try the following
Application.Run wbMain.Name & "!subproc"

Or maybe you have just used wbName as an example of your workbook name in
which case if your workbook name has any spaces in the name then enclose the
workbook name in single quotes.

Application.run "'wb Main'!subproc"



--
Regards,

OssieMac


"OffDev" wrote:

Please assist.

I have an userform that has several options button each calls a sub proc
from another workbook
I am getting run-time error 1004 Method Run of object_Application failed
when I click on the button when the other workbook close .

When the workbook is open I am getting run-time error 1004 Cannot run the
macro wbMain.xlsm!cmdOpenfile. The macro may not be available in this
workbook or all macros may be disabled.but with a different reason.
My macros options are enabled and has trusted access.

I am baffled because the code is very simple:

Application.run "wbMain!subproc"

Thanks
Offdev


OssieMac

Attempting to call a sub from another wb using a Userform opti
 
An afterthought.

If wbMain is a workbook variable then if there are any spaces in the
workbook's name then you will also need to include the single quotes in the
line of code as per one of the following examples.

Application.Run Chr(39) & wbMain.Name & Chr(39) & "!subproc"

Application.Run "'" & wbMain.Name & "'" & "!subproc"

--
Regards,

OssieMac




All times are GMT +1. The time now is 01:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com