+ Reply to Thread
Results 1 to 7 of 7

Code to create a new workbook that also includes code

  1. #1
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Code to create a new workbook that also includes code

    Hi. I have a macro that creates a new workbook and copies data over to it. I also want this macro to create a macro in the new workbook that is called from a button on one of the worksheets in the new workbook so that ultimately the new workbook will have it's own macro code. I haven't got the faintest idea how to create code in a new workbook with VBA. I actually can't even think how to search for this in the forum or Google. Any guidance to get me started will be greatly appreciated. Thanks all.
    Last edited by kadeo; 10-14-2014 at 05:16 AM. Reason: Altered Title

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Code to create a new workbook that also includes code

    Couldn't you use a template workbook with the code already in it?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Re: Code to create a new workbook that also includes code

    Quote Originally Posted by Norie View Post
    Couldn't you use a template workbook with the code already in it?
    This is probably what I'll end up doing if I can't do what I originally wanted. The first workbook is going to be distributed though and it seems a bit messy to have to distribute two.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Code to create a new workbook that also includes code

    Perhaps a template worksheet, with the button and code, in the distributed workbook then?

  5. #5
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Re: Code to create a new workbook that also includes code

    Quote Originally Posted by Norie View Post
    Perhaps a template worksheet, with the button and code, in the distributed workbook then?
    Ok, better, warmer, liking the sound of that. I guess I could hide that worksheet from view in the original workbook. The code then, if I put that in the sheet object instead of as a module where I'd normally put it, would it just go with the sheet when it's copied? Is that right? The code will only perform a copy of data to an already existing workbook so is it not important to have that in a module? Self taught with VBA but still don't fully understand why a code would need to reside in an object, a module or a class module.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Code to create a new workbook that also includes code

    Yes the code would need to go in the sheet module and you would need to use an ActiveX button on the sheet.

    If that won't work for you it is possible to create code using code but that would require changed in the users security settings.

  7. #7
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Re: Code to create a new workbook that also includes code

    Ok Norie, I'm gonna give that a go and see how successful it is.

    Quote Originally Posted by Norie View Post
    ...it is possible to create code using code but that would require changed in the users security settings.
    Since my OP I've found references to something called VBIDE. Is this what you are talking about? The users security settings should already be ok as they've all been set up to "Enable all macros" and "Trust access to the VBA project object model" in The Trust Center already.

    Thanks very much for your help Norie!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Editing a Macro to include multiple rows and include text formatting for leading zeros
    By missmea2005 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-04-2014, 09:50 AM
  2. [SOLVED] automatically include private sub in new workbook
    By Thirsa in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-13-2013, 12:27 PM
  3. Macro's in an excel 2007 workbook need to include drop down formating
    By JPayne@nbri in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2013, 04:23 PM
  4. Include Worksheets From Workbooks into ONE new Workbook
    By tcgaines in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-15-2005, 03:50 PM
  5. Replies: 2
    Last Post: 08-05-2005, 01:05 AM

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