Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Using the system AppData variable in VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NZ VBA Developer - 28 Sep 2007 04:02 GMT
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?

Signature

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...

Russ - 28 Sep 2007 07:54 GMT
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"

> OK Kids, here's the problem:
>
[quoted text clipped - 43 lines]
> Obviously the change needs to be someplace in the line that sets the value
> for SearchPath. A little help please?

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

NZ VBA Developer - 28 Sep 2007 09:59 GMT
You beauty Russ! That's got it. 'Twas the Environ() function that I was
missing from my knowledge base.
Signature

Cheers!

The Kiwi Koder

> 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()
[quoted text clipped - 57 lines]
> > Obviously the change needs to be someplace in the line that sets the value
> > for SearchPath. A little help please?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.