p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Excel VBA (http://p2p.wrox.com/forumdisplay.php?f=79)
-   -   Path for a template in VBA (http://p2p.wrox.com/showthread.php?t=6488)

Piblon November 21st, 2003 10:55 AM

Path for a template in VBA
 
Hi,
I am new to this group and have a problem that I can´t fix in any way at the moment. I start a template in a folder placed somewhere on the computer. After some VBA coding done with it, it will be saved as normal workbook. How is it possible to know the path to the template in VBA, it is easy with an workbook - ActiveWorkbook.Path, but that is not working with templates
Hope for some help in this issue.
Thanks in advance
Piblon


chrislepingwell November 21st, 2003 11:17 AM

Unless it is actual the .XLT file you have open for editing, the template doesn't have a path, because it hasn't been saved. It's exactly the same situation as when you open Excel, and have Book1 available - there is no saved file to have a path to.

HTH
Chris


There are two secrets to success in this world:
1. Never tell everything you know

Piblon November 21st, 2003 11:24 AM

Thanks

It is a xlt-file. then I will have to make the "Template" as a xls-file (read-only) as a possible solution.


chrislepingwell November 21st, 2003 11:38 AM

Why do you want to know the path to the XLT file in the first place? What are you trying to do?

Piblon November 26th, 2003 10:18 AM

Well, im doing a kind of production reporting programme.
Each month ýou start the template, answer a couple of questions and then the template will save into a normal workbook with a filename depending on the answers from the questions.
This is a bit of the code so you know what I mean
docName = Application.GetSaveAsFilename(fileName, "Excel Workbook (*.xls), *.xls", , "Save Stop Report")
ActiveWorkbook.SaveAs docName, xlWorkbookNormal


Quote:

quote:Originally posted by chrislepingwell
 Why do you want to know the path to the XLT file in the first place? What are you trying to do?

chrislepingwell November 26th, 2003 10:52 AM

OK, if that's what you are doing, I don't think you actually need the template's path. What you can do, if you want, is to set
Code:

filename = curdir
, and this will use the last directory used as a starting point. Alternatively, just set a default save location in code, preferably not the same directory as the template - you don't want users breaking things :)
BTW, bear in mind that users can cancel out of the dialog, returning "false", so you must trap that before attempting the save.


There are two secrets to success in this world:
1. Never tell everything you know

Piblon November 27th, 2003 01:27 AM

Thanx, I will try it out.
I know that cancel = False and working on trapping that issue as well.
Quote:

quote:Originally posted by chrislepingwell
 OK, if that's what you are doing, I don't think you actually need the template's path. What you can do, if you want, is to set
Code:

filename = curdir
, and this will use the last directory used as a starting point. Alternatively, just set a default save location in code, preferably not the same directory as the template - you don't want users breaking things :)
BTW, bear in mind that users can cancel out of the dialog, returning "false", so you must trap that before attempting the save.


All times are GMT -4. The time now is 09:08 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.