Embed Template Within File

  • Hi Everyone,


    I have a file with two sheets - Main and Reference. The file has a macro that when used from Main sheet displays some data (images to be specific) from the Reference sheet. The main sheet is of a specific format and has some buttons to call the macro.


    I want to have the capability to create any number of main sheets of the same format. I know this can be done by saving the Main sheet as a template and right clicking on a sheet and clicking 'Insert..'. But that would require the template to be stored in the excel start file on the local computer.

    I want to know if there is any way the worksheet template can be stored within an excel file, so that if the file is sent to people on a different computer, the user can easily add more worksheets using the template?


    Thanks.

    :angrypc:

  • Re: Embed Worksheet Template Within File


    If a Worksheet is added to a Workbook and sent elsewhere the Template Worksheet will exist in the sent file. However, it will not be readily available to the recepient.


    Why not create the no-data template in the Workbook, make it XlVeryHidden and use the [woe]*[/woe] to save the template to the users template folder?

  • Re: Embed Worksheet Template Within File


    Quote

    I want to know if there is any way the worksheet template can be stored within an excel file, so that if the file is sent to people on a different computer, the user can easily add more worksheets using the template?


    Yes.


    I would store the template worksheet within the selfsame workbook as an invisible worksheet.


    Your method of user accessibility is up to you. My opinion? On workbook open, check for the existence of this template in the templates folder. If it does not exist, create it automatically. Now this template is available when the user browses the templates folder.


    Another option would be to add a menu item directly below "Insert" such as "Insert New Main". This would insert a copy of the invisible worksheet into the workbook without the need for browsing all available templates.


    Which way do you want to go?

    Tom

  • Re: Embed Worksheet Template Within File


    Thanks Tom.


    I would prefer the second option. It would be easier for the user. So could you tell me how to add this option into the menu & how is the worksheet stored as an invisible sheet?



    :angrypc:

  • Re: Embed Template Within File


    You will need to do five things to set this up.

    • Add the worksheet that will serve as a template to your workbook if it is not already there.
    • Copy and paste the code listed below into "The Workbook Class". The default name of this class is "ThisWorkbook"
    • Within the code below, see Private Const ButtonCaption As String = "Insert My Template". "Insert My Template" is the caption that will be displayed on your button. Edit to suit.
    • Also within the code below, see With Sheets("TemplateMain"). "TemplateMain" is the actual tabname of your soon to be hidden template worksheet. Do one of two things.

      • Rename the template worksheet to = "TemplateMain" or...
      • ...change "TemplateMain" within the code to reflect the correct name as seen in the tab of the worksheet.


    • Save and close the workbook. Upon reopening, the button will be added and the template worksheet will be very hidden.


    If all else fails, see the link to an example workbook using the exact code as listed.


    TemplateWorksheet.zip


    Tom

  • Re: Embed Template Within File


    It definitely would not hurt to add:
    Application.ScreenUpdating = True at the end.


    Nevertheless, in a procedure that is running solo in the stack it is not neccesary. It will go back to true when the procedure is finished...

    Tom

  • Re: Embed Template Within File


    Well... I tried to edit my previous post and add the line, "Application.ScreenUpdating = True", but there is a 60 minute window to edit posts.

    Tom

  • Re: Embed Template Within File


    Thanks guys, it works perfectly!


    Just for my own understanding, if I was to put the button in the menu on the top (with File, Edit, View etc), then does the code have to change significantly?

    :angrypc:

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!