Closed Thread
Results 1 to 12 of 12

Code in 'ThisWorkbook' module in add-in?

  1. #1
    Forum Contributor
    Join Date
    04-18-2009
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2016
    Posts
    269

    Code in 'ThisWorkbook' module in add-in?

    Hi All,

    I have made a macro that displays a textbox containing the contents of a cell once the cell is clicked. The macro is written in the 'ThisWorkbook' module in the Sub 'Worksheet_SelectionChange'.

    Now I want to convert this macro into an add-in so that it works on all the Excel workbooks I open. Is it possible to do this? Or is there a way in which we can automatically put the code in the 'ThisWorkbook' module of any open worksheet (doesn't seem feasible).

    If you have any ideas, please let me know?

    This query was posted yesterday by Vaibhav. Please find it here.

    Regards,
    Karan
    Last edited by VBA Noob; 04-29-2009 at 06:07 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Code in 'ThisWorkbook' module in add-in?

    Or is there a way in which we can automatically put the code in the 'ThisWorkbook' module of any open worksheet (doesn't seem feasible).
    It is, and there was a recent example on the forum, but I don't think you want to do that. I think you want to put it in a class module in the add-in:
    Please Login or Register  to view this content.
    See http://www.cpearson.com/excel/Events.aspx
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    01-13-2009
    Location
    Mumbai
    MS-Off Ver
    Excel 2003, 2007
    Posts
    168

    Re: Code in 'ThisWorkbook' module in add-in?

    Wow!! It's amazing..

    I din't knew you one can do so much with the use of classes and events in VBA..

    Thanks shg.. that indeed has opened new ways to solving problems..
    Last edited by c.vaibhav; 04-29-2009 at 02:07 PM.

  4. #4
    Forum Contributor
    Join Date
    04-18-2009
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2016
    Posts
    269

    Re: Code in 'ThisWorkbook' module in add-in?

    Hey shg,

    That helped a lot!!! I am able to do it using Class Module.

    Thanks a lot!!!

    --Karan--

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Code in 'ThisWorkbook' module in add-in?

    Good job, karan, Wouyld you post your solution? This is not something that we do a lot of in the forum, and we'd all like to see what you did.

  6. #6
    Forum Contributor
    Join Date
    04-18-2009
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2016
    Posts
    269

    Thumbs up Re: Code in 'ThisWorkbook' module in add-in?

    Okay. Here is the solution that I figured out as a result of the guidance provided by Shg . This is how it works:

    In the add-in, you add a Class Module and name it 'CWorksheetObject'. In this class module, you write the following code:
    Please Login or Register  to view this content.
    In the add-in, you add a Module and write the following code in it:
    Please Login or Register  to view this content.
    Everytime you run the macro 'TestProc', the code which you wrote in the Class Module in the add-in works on any open workbook.

    I am attaching an add-in to make the understanding easier for all those interested. Install the add-in by putting it in the relevant folder, followed by opening Excel and going to Tools >> Add-ins and selecting the add-in (its name is 'TextBox Popup Addin.xla'). It will create a Toolbar button in Tools (by the name 'TextBox Popup'). Now, everytime you open Excel and click on 'TextBox Popup', and click on any cell in the open Excel sheet that has some data, a textbox pops up with all the cell contents.

    Any questions, do write back

    Regards,
    Karan
    ------------------------------------------------------------------------
    Well, I just realized that we cannot attach an xla file (add-in) . Moderator, is there a way I can do it? If I upload it on Rapidshare, it won't stay there for more than 30 days I guess. Please let me know what to do.

  7. #7
    Forum Contributor
    Join Date
    04-18-2009
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2016
    Posts
    269

    Thumbs up Re: Code in 'ThisWorkbook' module in add-in?

    Well, I just realized that we cannot attach an xla file (add-in) . Moderator, is there a way I can do it?
    I am attaching a '.xls' file. Whoever wants to see how the above thing works, you can save the file as a '.xla' file with the same name, i.e. 'TextBox Popup Addin.xla' and follow the steps mentioned in the above post.

    And somebody please check if it works in Excel 2007. I have tried it only in 2003.

    --Karan--
    Attached Files Attached Files

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Code in 'ThisWorkbook' module in add-in?

    Thank you, karan.

    BTW, you can zip and attach any kind of file.

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code in 'ThisWorkbook' module in add-in?

    Karan

    Excel 2007 does not have Commandbars so it will not attach to he Tools Commandbar.

    The addin can be found in the addins tab, the textbox is still creted
    Last edited by royUK; 05-01-2009 at 02:19 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code in 'ThisWorkbook' module in add-in?

    I have converted the addin to run with Excel 2007. A new tab is created - "TextBox Poup", there is one button in the tab to replace the one added to the Toolbar menu.

    It should also run in earlier versions, adding the button to the Tools menu as the original did.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    04-18-2009
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2016
    Posts
    269

    Thumbs up Re: Code in 'ThisWorkbook' module in add-in?

    Roy and Shg,

    Thanks a lot!!!

    Regards,
    Karan

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code in 'ThisWorkbook' module in add-in?

    To correctly install an addin in 2007 read this

    http://www.excel-it.com/Excel%202007...tall-addin.htm

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1