SpecialFolders

User avatar
ErikJan
BronzeLounger
Posts: 1254
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

SpecialFolders

Post by ErikJan »

I'm using a script to place templates and themes (for Office) in the Templates folder. I'm using the "SpecialFolders" call. I thought I had it right by using this:

whshell.SpecialFolders("Templates")

But I'm getting:

C:\Users\myUserID\AppData\Roaming\Microsoft\Windows\Templates

and no the one I need which is this one...

C:\Users\myUserID\AppData\Roaming\Microsoft\Templates

Is there a call that gives me the right (last) path?

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SpecialFolders

Post by HansV »

In Word:

Application.Options.DefaultFilePath(wdUserTemplatesPath)

In Excel:

Application.TemplatesPath
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1254
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: SpecialFolders

Post by ErikJan »

Yep, this is a VBS script file however (I need to copy some template files etc. to users), so how do I do it there?

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SpecialFolders

Post by HansV »

You could use Automation:

CreateObject("Excel.Application").TemplatesPath
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1254
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: SpecialFolders

Post by ErikJan »

Ended up using this:

WSHShell.SpecialFolders("AppData") & "\Microsoft\Templates"

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SpecialFolders

Post by HansV »

That will only work if the user hasn't changed the location of the user templates folder. It can be changed in the Options dialog for Word (Word 97-2003: File Locations tab; Word 2007-2010: Advanced, File Locations button in the General section).
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1254
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: SpecialFolders

Post by ErikJan »

OK, but using Excel to get a path seems like overkill; is there no 'simple' way in VBScript then??

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SpecialFolders

Post by HansV »

Problem is that if the user hasn't changed the path, the registry entry just says "Templates", which tells Office to look in the default location. If the user has changed it, the registry entry contains the full path. So reading the registry entry is not a straightforward solution.

It is HKEY_CURRENT_USER\Software\Microsoft\Office\n.0\Common\General\Templates, by the way, where n is the internal Office version number (8 = Office 97, ..., 14 = Office 2010, no version 13).
Best wishes,
Hans

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: SpecialFolders

Post by agibsonsw »

I suppose you could consider reading the Registry (RegRead?) for the templates' paths, although you may find that you don't have access to the users' registry - discussed here.

Also, the registry key won't exist if the default location(s) haven't been changed. In which case you would need to construct the default location, inserting the user's name.

Something like:

Code: Select all

‘HKEY_CURRENT_USER = HKCU
‘HKEY_LOCAL_MACHINE = HKLM
‘HKEY_CLASSES_ROOT = HKCR
‘HKEY_USERS = HKEY_USERS
‘HKEY_CURRENT_CONFIG = HKEY_CURRENT_CONFIG
Dim objRegistry, Key, ReadReg
Set objRegistry = CreateObject(”Wscript.Shell”)
Key = objRegistry.RegRead("HKCU\Software\Microsoft\Office\12.0\Common\General\UserTemplates")
ReadReg = Key
But refer to Hans' recent post as well. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.