+ Reply to Thread
Results 1 to 8 of 8

Generate a "Workbook Open" Macro in new worksheet Programmaticly

  1. #1
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Generate a "Workbook Open" Macro in new worksheet Programmaticly

    Hello, I have searched to find the answer myself but I just can't seem to find what I am looking for. I have a LARGE Workbook that I call a "Program" because it has lots of Userforms that I use to enter data in and then at the end it generates a new Workbook based on what I typed in all without the user ever even seeing an excel workbook,worksheet, or cell.
    One of the worksheets generated in this new workbook is what i call the "CONFIG" sheet and I use as a "CONFIG" file so that at a later date I can use the new workbook to re-load all that data back into my "Program" so I can generate a different workbook with it and not have to type all that data back in.....I hope that made sense..anyway all i need is a way to add a
    Please Login or Register  to view this content.
    to the new workbook automatically when the Macro generates it the first time. So that the user of the new workbook does not see it. If you have any questions let me know.
    Thank you for your time,
    Last edited by TheNewGuy; 03-10-2010 at 10:51 AM.

  2. #2
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: Generate a "Workbook Open" Macro in new worksheet Programmaticly

    Hi,

    You need to use VBE ...
    Take a look at Chip's excellent solution ...

    http://www.cpearson.com/excel/vbe.aspx

    HTH

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Generate a "Workbook Open" Macro in new worksheet Programmaticly

    Is there a reason you can't simply hide it when you create it? If there is, I would suggest using a template workbook with the code already in it (I am not a fan of writing code in code unless absolutely necessary).
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Generate a "Workbook Open" Macro in new worksheet Programmaticly

    Is there a reason you can't simply hide it when you create it? If there is, I would suggest using a template workbook with the code already in it (I am not a fan of writing code in code unless absolutely necessary).
    You know, that was my first thought as well so I tried Using that same line
    Please Login or Register  to view this content.
    Immediately after creating the new sheet, but it didn't work. Next time I opened the new workbook the CONFIG sheet was visible.

    I would suggest using a template workbook with the code already in it
    I tried this as well, I added the Workbook_Open code from above to my template file that I use and it didn't seem to do anything. --edit-- after modifying the template like you suggested when I manually insert the template it asks if I want to allow Macros, but then if I go to the VBA editor and look there is no Workbook_Open code in the new workbook, with the new worksheet I just inserted from the template..
    Last edited by TheNewGuy; 03-10-2010 at 09:40 AM.

  5. #5
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile Re: Generate a "Workbook Open" Macro in new worksheet Programmaticly

    Good afternoon TheNewGuy

    Try using this code :
    Please Login or Register  to view this content.
    Before you run it set a reference within the VBE to Microsoft Forms 2.0.
    Go to Tools > References, find and tck "Microsoft Forms 2.0 Object Library" and click OK.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  6. #6
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Generate a "Workbook Open" Macro in new worksheet Programmaticly

    JeanRage ,
    Hello, I think that you are correct and that I will need to use what you suggested, here is what I have so far.
    Please Login or Register  to view this content.
    I have not tried it yet does this look correct?

    The
    Please Login or Register  to view this content.
    part in is one part I am not sure about. Does the line
    Please Login or Register  to view this content.
    act like the line
    Please Login or Register  to view this content.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Generate a "Workbook Open" Macro in new worksheet Programmaticly

    You would need to use a template Workbook, not worksheet.
    If you try to hide the sheet in code when you create it, you should do two things:
    1. Specify which workbook you are manipulating:
    Please Login or Register  to view this content.
    2. Make sure you save the workbook afterwards!

  8. #8
    Forum Contributor
    Join Date
    06-01-2009
    Location
    Cincinatti,Ohio
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: Generate a "Workbook Open" Macro in new worksheet Programmaticly

    Thank you romper! for some reason the line of code i tried
    Please Login or Register  to view this content.
    does not work, however your line...
    Please Login or Register  to view this content.
    DOES work!
    Thank you very much for your help!

+ Reply to 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