Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Selection.OnAction assignment from another workbook VBA

Posted on 2010-09-05
1
Medium Priority
?
1,429 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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

926 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