Using the system AppData variable in VBA

N

NZ VBA Developer

OK Kids, here's the problem:

Client's IT elves have put together a deployment packages for rolling my
sweet-as templates to the unwashed masses. This package puts my masterpieces
into a folder the generic User templates location: 'C:\...\Application
Data\Microsoft\Templates'. And in my code I look for my templates in the
location specified in Word for the User templates
('Options.DefaultFilePath(wdUserTemplatesPath)' plus the name of the special
folder). All choice to this point.

However, the users have quite a bit of autonomy when it comes to configuring
their computers. Consequently, it's possible and highly likely that some of
the users will have changed their options in Word to look someplace other
than the standard, default, vanilla, as-installed location for User
templates. So it would make more sense for my code to look in
'C:\...\Application Data\blah...blah...blah', yes? Of course that location
varies by user, but the client's elves assure me that I can use the same
method they use for the deployment: look at the AppData variable.

Except I don't know how to put that into my code...

Here's a snippet that shows how things work at the moment:

Private Sub Templates
Dim SearchPath as String
SearchPath = Options.DefaultFilePath(wdUserTemplatesPath) & "\Standard
Templates\"
Call GetTemplates(SearchPath)

Private Sub GetTemplates(Path$)
Dim SearchTemplates$
SearchTemplates = Dir(Path & "*.dot*", vbNormal)
Do While SearchTemplates <> ""
If InStr(SearchTemplates, "~") = 0 Then
If Right(LCase(SearchTemplates), 4) = ".dot" Then
frmTemplates.ListBoxTemplates.AddItem Mid(SearchTemplates, 1,
Len(SearchTemplates) - 4)
Else
frmTemplates.ListBoxTemplates.AddItem SearchTemplates
End If
End If
SearchTemplates = Dir
Loop
End Sub

Obviously the change needs to be someplace in the line that sets the value
for SearchPath. A little help please?

--
Cheers!

The Kiwi Koder
Little know fact: Romania has been in every Rugby World Cup. After the play
the ABs they'll wish they missed this one...
 
R

Russ

Here are links about system variables. Find out which one they are going to
use exactly, then you can build up your path using the VBA Environ()
function to access the system variables and the path to your deployed
templates.

http://vlaurie.com/computers2/Articles/environment.htm
and
<http://technet2.microsoft.com/WindowsVista/en/library/3f1be40e-70c6-462c-9e
8f-591d14d875cd1033.mspx?mfr=true>

For example:
strDrive = Environ("HOMEDRIVE")
strPathDocs = strDrive & Environ("HOMEPATH") & "\My Documents"
 
N

NZ VBA Developer

You beauty Russ! That's got it. 'Twas the Environ() function that I was
missing from my knowledge base.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top