Consulting

Results 1 to 10 of 10

Thread: How to identify workbook?s name?

  1. #1

    How to identify workbook?s name?

    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.

  2. #2
    VBAX Tutor
    Joined
    Jan 2005
    Location
    Greenville, SC
    Posts
    220
    Location
    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

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Try activeworkbook. Thisworkbook refers to the addin and ActiveThisWorkbook doesn't exist as far as I know.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    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.

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why don't you post your code and put us all out of our misery?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    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.

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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..._custom_menus/

    This is what I use on all of my addins.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #10
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •