Application.run error 1004

sheekom

New Member
Joined
Oct 10, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,
I am trying call VBA code from another worksheet in another workbook and It get error 1004. Can not figure out, and would appreciate help. here is my code:

Public Sub RunSheetMacro()
Dim Obj As Object
Dim wbk1 As New Workbook
Dim wks1 As New Worksheet
Set wbk1 = Application.Workbooks("Management of Academy Topics.xlsm")
Set wks1 = wbk1.Sheets("oea_TopicsLibrary")
wbk1.Activate
wks1.Select

'RunString = "'" & wbk1.Name & "'!" & wks1.Name & "." & "updateTopicLib, obj"
'Debug.Print RunString

Application.Run "'Management of Academy Topics.xlsm'!oea_TopicsLibrary.updateTopicLib"

End Sub

The VBA code routine is in sheet oea_TopicsLibrary of workbook Management of Academy Topics.xlsm and the routine name is updateTopicLib. I know I am something wrong here in syntax. Can it work ? Would appreciate any direction.

Thanks in Advance
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Welcome to the Board!

Which line of code gives you the error?
Is the other file already open?
Is it open in the same session of Excel, or a different session (they need to both be in the same Excel session)?
 
Last edited:
Upvote 0
Yes, All workbooks are open. I get error on application run line. It is in the same Excel session.
 
Upvote 0
When you say:
The VBA code routine is in sheet oea_TopicsLibrary of workbook
do you mean that the code is in the oea_TopicsLibrary sheet module in VBA?

I think in order to access it from other workbooks/worksheets, it needs to be put in a General module, and needs to be marked as "Public".
 
Upvote 0
Hi Joe4,

Thanks for the reply and made me realize that (for the benefits of all who visit this thread)

1. VBA code can be worksheet specific,i.e. in a addin module (".xlam") or in a General Module (can be called anything like (WbkCodeModule) of a workbook. Workbook general module is created by create a module action at the workbook level in VBE.
2. Worksheet specific VBA code/Macro can be called only in that specific worksheet only.
3. addin module (*.xlam) code can be called from anywhere across worksheets and workbooks and must be public.
4. Any worksheet can call general module code from within same workbook or different workbook. The Call syntax is different as follows:

From same workbook - Call MacroName
From different workbook Call "'WorkbookName'!MacroName" - Note the single quite around the workbook name and double quote around the entire call string. The workname and macroname can be created dynamically or passed in a general purpose external macro calling routine and again must be placed in the general module.

5. Parameters can be passed in both above cases

Once I realized and followed above rules. All is good ! Thanks
 
Upvote 0
You are welcome.
Glad to hear that you got things working!
 
Upvote 0

Forum statistics

Threads
1,224,833
Messages
6,181,240
Members
453,026
Latest member
cknader

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