 |
| Excel VBA Discuss using VBA for Excel programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 21st, 2003, 10:55 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 21st, 2003, 11:17 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 21st, 2003, 11:24 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks
It is a xlt-file. then I will have to make the "Template" as a xls-file (read-only) as a possible solution.
|
|

November 21st, 2003, 11:38 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Why do you want to know the path to the XLT file in the first place? What are you trying to do?
|
|

November 26th, 2003, 10:18 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|
|

November 26th, 2003, 10:52 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
, 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
|
|

November 27th, 2003, 01:27 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
, 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.
|
|
|
 |