PDA

View Full Version : How to identify workbook?s name?



bruno.barret
01-14-2009, 09:32 AM
Hi Guys.
I need your help.
I need to distribute a macro.
I am planning to creat an add-in.
This macro creates a button in the workbook that runs it.
My problem is: The Macro in the add in can?t identify the workbook?s name (the workbook that is calling).
Instead of creating the button in the main workbook it is creating inside the add in sheet.
I tried to use ThisWorkBook and ActiveThisWorkbook commands, but it doesn?t work (it gives me back the add in workbook?s name)

If I could creat a way that when the add in runs, it identifies the name of the workbook that is calling it, I could use this procedure in my VBA code, and the button would appear in the right place.

Any ideas?

Thank you.

daniels012
01-14-2009, 09:47 AM
No sure what all your code is, but can you use something like:
Me.Activecell............
Me Identifies the workbook you are currently in, or am I misinterpreting what you are saying?

Michael

lucas
01-14-2009, 09:53 AM
Try activeworkbook. Thisworkbook refers to the addin and ActiveThisWorkbook doesn't exist as far as I know.

bruno.barret
01-14-2009, 09:53 AM
The problem is, that this way will identify the Add in workbook. I need to identify the main workbook, the one that I want to install the add, create a button and allow me to run in and the macro just clicking in the button.

lucas
01-14-2009, 09:56 AM
You don't install the addin into another workbook. It, when installed and if your code references activeworkbook will work on whatever workbook is open.

Same for your menu. When installed the menu will always show when you open Excel.....available to all workbooks you open.

lucas
01-14-2009, 09:57 AM
You do need to create your menu with code however. Just using customize and adding a menu will not make it be a part of your addin, just a part of your excel application.

Bob Phillips
01-14-2009, 10:50 AM
Why don't you post your code and put us all out of our misery?

bruno.barret
01-14-2009, 11:02 AM
I can post it, but I don?t think it will help you.
But the probem is quite simple.
The add-in is related to a macro.
When I install the add-in, I want it to creat a button in the workbook to run the macro whenever I want.

The problem is just one: I can?t create the button in the right place. I want to distribute this (macro add-in), I need to install it in different workbooks with different names.
But the add-in always identify itself workbook name.
I need a code for this add-in to be able to identify the workbook that I?m installing it ( add-in), and then create the button that will run the macro.

lucas
01-14-2009, 11:19 AM
Well, if you create an addin that creates a button then the button will always be there when the addin is installed, no matter what you are doing. Why not use a menu item...you know, next to help on the main menu.

check this out, set up your menu and use this in your addin. When it's installed you will have the menu to run your macro's.

http://spreadsheetpage.com/index.php/tip/creating_custom_menus/

This is what I use on all of my addins.

Kenneth Hobs
01-14-2009, 11:24 AM
Did you Attach your toolbar with the button(s) to run it to your add-in?

When you edit the button to Assign a macro, it would reference your add-in and macro. As Lucas said, that macro's code would then use ThisWorkbook to reference itself and ActiveWorkbook as needed.