Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve starting folder of template once loaded

Status
Not open for further replies.

getochkn

Programmer
Sep 28, 2001
8
CA
I have a pretty nifty Invoice sheet that I've done that keeps track of the last used invoice number by writing to a cell in the file, saves the file with a name and that number, and then clears the data and saves the template again with the last used invoice number. Everything works great, the only problem is when it goes to save the new invoice and the modified template, it always wants to save it back to my documents and not the starting directory where the template was launched. Now I know that as soon as the template is opened, I get a 'invoice1.xls' file that hasn't been saved and therefore reverts to 'my documents' Is there anyway to retireve the name of the folder where the template was initially started from? For now, I have it in a cell value and that works fine, I'm just trying to make this as dynamic as possible so that if it gets moved, it would automatically just use the new folder for everything. It's a small point and everyone else is happy with it but it still bugs me. Thanks for any help.
 
This come up with the full path of the template. You could then use that as the path, when saving the file created by the template, replacing the template name of course. I put that in just for completeness in getting the full path of the template.

Dim TemplateFilePath As String
Dim curTemplate As Template
Set curTemplate = ActiveDocument.AttachedTemplate
TemplateFilePath = curTemplate.Path & Application.PathSeparator _
& curTemplate.Name

However, I have to ask, why would you want to put the new file in the folder the template was launched from? Templates, I think, should be kept separate from documents they generate. But hey, maybe there is a good reason why you would want to have them together.


Gerry
 
Basically it's just the way I started it, I may put the template in a different spot, it's not final yet. I tried your code example but I get the VBA error, 'user type not defined' on the Dim curTemplate As Template line.
 
Ah, it seems the ActiveDocument.AttachedTemplate is only a Word thing and not an Excel method or property. Does anyone have any Excel answers to this?
 
Sorry, in Excel "Application.TemplatePath" returns the local path where templates are stored. Read only string.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top