Solved

Selection.OnAction assignment from another workbook VBA

Posted on 2010-09-05
1
1,306 Views
Last Modified: 2012-06-21
Experts,

I am running an Excel 2007 addin file "Irwinconsult Menu.xlam" which contains a section of script to assign a macro to a button contained within another excel workbook (the macro being assigned to the button is also contained within the other workbook).  Part of the code is as follows:

Windows(New_Pan_Workbook).Activate
ActiveSheet.Shapes("Button 115").Select
Selection.OnAction = "create_new_pan"

Note:  New_Pan_Workbook is assigned as the part of the other workbook earlier in the code.  

The problem with the Selection.OnAction script above is the because it is executed by Irwinconsult Menu.xlam, the button assignment ends up being "'Irwinconsult Menu.xlam'!create_new_pan"  instead of simply "create_new_pan".  

The other complication is that the name and path of the other workbook varies but this is dealt with using the  ActiveWorkbook.Path and .Name earlier in the code.

Any thoughts?

Jason
0
Comment
Question by:irwinconsult
1 Comment
 
LVL 11

Accepted Solution

by:
jkpieterse earned 500 total points
ID: 33609146
If the macro you're calling is in the same workbook as the code that creates it:

Selection.OnAction = "'" & ThisWorkbook.FullName & "'!create_new_pan"

Note the single quotes!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question