+ Reply to Thread
Results 1 to 7 of 7

VBA that copies module and code into a new workbook

  1. #1
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    VBA that copies module and code into a new workbook

    HI Guys!

    I'm running into some problems with this macro I found online. I think I adjusted everything to suit my needs, which is to copy module2 with the macro's it contains into a new workbook. Somehow this code is not doing anything though. No code is transferred to the example file.

    Hope you can help out!

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: VBA that copies module and code into a new workbook

    if you step through the code, what happens when you execute the line

    Please Login or Register  to view this content.
    with the on 'error resume next' commented out?
    Last edited by BellyGas; 12-18-2018 at 09:02 AM.

  3. #3
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92

    Re: VBA that copies module and code into a new workbook

    It says "Programmatic access to visual basic project is not trusted!

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA that copies module and code into a new workbook

    You need to enable it in Excel options - note that this is disabled for a reason and not really good practice.

    Don't expect other users to be able to run your code

  5. #5
    Registered User
    Join Date
    02-14-2017
    Location
    Hilversum, Netherlands
    MS-Off Ver
    2010
    Posts
    92
    Quote Originally Posted by Kyle123 View Post
    You need to enable it in Excel options - note that this is disabled for a reason and not really good practice.

    Don't expect other users to be able to run your code

    Is there another way how to achieve the same result? I would like to copy my macro in a New workbook

  6. #6
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: VBA that copies module and code into a new workbook

    A possible workaround would be to have the new workbook already set up with your code present and just copy data to it rather than a VBA module.

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA that copies module and code into a new workbook

    It's a bit hard to comment without more context, however a workbook template might be more appropriate, possibly and addin, or put the code in the sheet so that when the sheet is copied, it takes the VBA with it

+ 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. Replies: 7
    Last Post: 08-25-2018, 09:00 PM
  2. [SOLVED] Help with code to open files and copies them into another workbook
    By rv02 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-10-2018, 07:24 AM
  3. Error Handler Help for Code that Copies a sheet to a new workbook
    By caliskier in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-27-2014, 12:47 PM
  4. Create new workbook, module and code using vba
    By pgm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-12-2012, 06:03 PM
  5. [SOLVED] VBA code to execute a module in a different workbook
    By Need_help_please in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-06-2012, 06:27 AM
  6. how to access Sheet module, normal module, Worbook module to type code
    By alibaba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2009, 07:51 AM
  7. Run worksheet module code from workbook module?
    By keithb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2005, 12: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