Template

  • Thread starter Thread starter nc
  • Start date Start date
N

nc

Hi

In my VBA code I am referencing Template1. The problem
is sometimes the template opens as Template2/3/4 etc. and
I get an error message. Is there a way of referencing
templates to avoid errors.

Thanks.
 
Maybe you could use ThisWorkbook if the code is in the workboook based on that
template.

If you're opening the template from another macro, you could use a variable that
represents that new workbook and use that:

Dim wkbk As Workbook
Set wkbk = Workbooks.Add(template:="C:\my documents\excel\book1.xlt")
wkbk.Worksheets(1).Range("a1").Value = "hi"
.....
 
Hi Dave

Thanks a lot. It solved my problem.

-----Original Message-----
Maybe you could use ThisWorkbook if the code is in the workboook based on that
template.

If you're opening the template from another macro, you could use a variable that
represents that new workbook and use that:

Dim wkbk As Workbook
Set wkbk = Workbooks.Add(template:="C:\my documents\excel\book1.xlt")
wkbk.Worksheets(1).Range("a1").Value = "hi"
.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top