Macro to create new worksheet from template when template in same directory as excel file.

rxp19

New Member
Joined
Jul 4, 2011
Messages
5
I'm sure this is a really easy question to answer.

I have a macro that creates a new worksheet from customtemplate.xltm

The code works fine.

Unfortunately, I can't really send this workbook to others without having to hardcode the location of the template.

The (partial) code I'm using includes:

Sheets.Add(After:=Worksheet, Type:="C:\Users\MyUserName\Desktop\customtemplate.xltm")

I would like the code to be something to the effect of:

Sheets.Add(After:=Worksheet, Type:="[current directory of workbook]\customtemplate.xltm")

what is the proper way to write this in a macro?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I found this to retrieve the current directory

ThisWorkbook.Path

But I'm not sure where/how to apply that to the macro
 
Upvote 0
Try something like this...
Code:
Sheets.Add(After:=Worksheet, Type:=ThisWorkbook.Path & "\customtemplate.xltm")
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top