We're aware that some users are experiencing technical issues which the team are working to resolve. See the Community Noticeboard for more info. Thank you for your patience.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

How do I package up a VB Excel macro??

Options
Hi all,


I've written a series of VB Excel macros in one Excel workbook.

I would like to use the same macros on different workbooks in future.

So I need to know how I can package up the macros and have them sit somewhere independent of the workbook they are in now. I do not known of a way to take the code and put it somewhere outside all workbooks.

I'm new to VB Excel - so apologies for the novice question.

Thanks!
"To be ignorant of one's ignorance is the malady of the ignorant." Amos Bronson Alcott

Comments

  • have a quick look at THIS FORUM , as they seem to have discussed exactly what you are looking for.
    I haven't been asked to tell you that I'm the [highlight]Board Drunk[/highlight] for this board. As the night wears on, my posts will become worse, with simple spelling mistakes, inane ramblings, and a blatant disregard for the truth. I have no authority to do anything, so there's no point asking or telling me. If you see me past midnight, please tell me to get my coat and order me a taxi.

    Free Ebay Simple Profit/Loss Spreadsheet. PM me for a download link.
  • londonman81
    londonman81 Posts: 1,130 Forumite
    Part of the Furniture 500 Posts Name Dropper Combo Breaker
    have a quick look at THIS FORUM , as they seem to have discussed exactly what you are looking for.

    It looks like the question in that forum is slightly different to mine......

    Just to make mine clearer - Im not looking to make a stand alone program out of my macro - I just want it to run on other workbooks within Excel.

    As usual - the simplest things seem to be impossible - and I've look in all the supposedly good books/websites .....they dont seem to cover such basic things......


    It must surely be possible to package up a macro so it can be used on other workbooks in future?!
    "To be ignorant of one's ignorance is the malady of the ignorant." Amos Bronson Alcott
  • DVB_3
    DVB_3 Posts: 346 Forumite
    After you have created your macro(s), open it (them) in Visual Basic Editor. From there (File menu) you can both export and import them.
  • feival
    feival Posts: 469 Forumite
    Part of the Furniture Combo Breaker
    You simply need to save the macros into your personal.xls which is the template spreadsheet that opens when you start a blank spreadsheet. This is the same file that stores your custom tool bars as well as personal macros.
  • Chippy_Minton
    Chippy_Minton Posts: 3,339 Forumite
    It looks like the question in that forum is slightly different to mine......

    Just to make mine clearer - Im not looking to make a stand alone program out of my macro - I just want it to run on other workbooks within Excel.
    Nope, the clue is in the 2nd reply in londonman81's link. You'll need the Visual Basic IDE to create and compile a .DLL containing your functions. Then in the Excel VBA editor you reference your .DLL by clicking Tools - References - Browse to your .DLL.

    Now I guess your .DLL functions could contain just 'pure' VB code or reference Excel objects like Worksheet, Cell etc.

    For the former you might have a function in your DLL called AddTwoCells(cell1 as integer, cell2 as integer). This would be called in your Excel VBA using AddTwoCells("A1".Value, "A2".Value).

    For the latter, it might be AddTwoCells(cell1 as Excel.Cell, cell2 as Excel.Cell) and your Excel VBA would pass the cell object as the function arguments: AddTwoCells("A1","A2"). Your VB .DLL can then access the Excel cell properties as required.

    I've forgotten the Excel syntax and object names for referencing a cell or its value, but hope the above description of the 2 techniques makes sense.
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 351K Banking & Borrowing
  • 253.1K Reduce Debt & Boost Income
  • 453.6K Spending & Discounts
  • 244K Work, Benefits & Business
  • 598.9K Mortgages, Homes & Bills
  • 176.9K Life & Family
  • 257.3K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.1K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.