PDA

View Full Version : Find Template Path



BlueDNA
04-19-2006, 09:24 PM
Hi all,

A very easy one that can hopefully be solved quite quickly.

How do you get the full Path of an opened .xlt file?

In .xls files i use:


Dim wbk As Workbook
MsgBox wbk.Application.ActiveWorkbook.Path


But when i change the file name extension to .xlt the msgbox shows blank.

Thanks so much!

David

BlueDNA
04-19-2006, 09:28 PM
Edit: I know a new instance of a template file has no path because it has not yet been saved, therefore wbk.Application.ActiveWorkbook.Path will not work. i.e. NewTemplate1

I've tried CurDir but it does not show me the full path that my NewTemplate.xlt is saved.

Hope this makes sense.

jindon
04-19-2006, 10:17 PM
Hi
try


with activeworkbook
msgbox .path & application.pathseparator & .name
end with

Jan Karel Pieterse
04-20-2006, 10:34 AM
Depends on how the xlt was opened. If you used Excel's file open dialog and browsed to the xlt and then opened it, you can use ActiveWorkbook.Path (which btw is better syntax than what you wrote).
If you doubleclicked the template in explorer or used File, New, then you're out of luck, there is no true connection between the workbook which has now been created based on the template and the location of the template. Hence there is no 100 % foolproof method to get at that location.

BlueDNA
04-20-2006, 03:00 PM
Depends on how the xlt was opened. If you used Excel's file open dialog and browsed to the xlt and then opened it, you can use ActiveWorkbook.Path (which btw is better syntax than what you wrote).
If you doubleclicked the template in explorer or used File, New, then you're out of luck, there is no true connection between the workbook which has now been created based on the template and the location of the template. Hence there is no 100 % foolproof method to get at that location.

So there is no way of getting the template path name even though I managed to msgbox out the workbook.name (NewTemplate1 and NewTemplate.xlt) and workbook.count was 2 in "new mode".

Thanks, jindon but that didnt work because im opening up the template in new mode, so it spawns a new template and has no real path until it has been saved.

What a bummer. Any work arounds?

Jan Karel Pieterse
04-20-2006, 09:53 PM
None that I know of, sorry.