Need Help Writing VB Code on a Template

T

TomP

When I open a template file and complete my entries, I would like to discard
all inputs made to that file and start over.

Question: Is there a way I can write a clode labeled "Reset" where Excel
will close and discard any changes to that file and reopens a new template
file?

For example... below I have a code written for MS Word and it works by
discarding the current file and reopens a new one. I just don't know how to
do it in MS Excel.

Dim LastDocument As Document
Set LastDocument = Active Document
OpenNewBlankDocument
LastDocument.Close SaveChanges:=wdDoNotSavechanges

Thank you,

Tom
 
G

Gord Dibben

Why do you want to discard changes?

If the file is a true Tempate(*.xlt) a new workbook is opened based upon
that Template.

The Template itself does not open so is not changed in any manner.


Gord Dibben MS Excel MVP
 
J

JLGWhiz

You would use the Workbooks.Open method. Most of this is spelled out in the
VBA help files which can be accessed in the VB editor mode. But as Gord
points our, if you are using a template with the .xlt suffix, then it
automatically creates a new workbook when you open it and the original
template reamains unchanged. So if you do not want to keep the changes you
make, just close it without saving and it will go away. You can then open
the original template and start all over.
 

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

Top