Solved

Selection.OnAction assignment from another workbook VBA

Posted on 2010-09-05
1
1,296 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now