Save As UserName

L

Lee

I have a template add-in which I need to save with a
username. The template automatically counts what templates
users access.

The code I have is:
'<----------------------Start of Module Code---------------
------------->
Option Explicit

Public gccTemplateUsageCounter As clsCounter

Public Sub AutoExec()
Const cCounterFileFullPath As String
= "M:\TECHNOLOGY\TemplateUsage\CountUsage\count_usage.cnt"

' Instantiate class to perform template usage counting
Set gccTemplateUsageCounter = New clsCounter

' Hook up event handler to that we can catch application
level events
Set gccTemplateUsageCounter.appWord = Word.Application

' Log the existing counter file (if any)
gccTemplateUsageCounter.Initialise cCounterFileFullPath
End Sub

(There is a lot of class modules code with this as well -
let me know if you need to view that).

The Line:
Const cCounterFileFullPath As String
= "M:\TECHNOLOGY\TemplateUsage\CountUsage\count_usage.cnt"
is where I need to put the username, e.g.
\CountUsage\username_count_usage.cnt

Any ideas? Do you need to see the full code? I am
running Word 2002. Thanks in advance.
 
D

dz

There are some very involved ways to derive the username.
However, the easiest way is to parse it from where the
normal template is stored. The following will give you
the bona fide username, not something that was a shortcut
in Word itself (unless the normal template was re-directed
to a non-default folder).

strPath = Application.NormalTemplate.Path

So, on my computer, this is what it provides:

C:\Documents and Settings\Administrator\Application
Data\Microsoft\Templates

So, you can parse what's between documents and settings\
and \applcation data.

Hope this helps.

dz
 
L

Lee

Hi. Thanks for your reply, however, I'm not sure exactly
what you are saying. I understand that the username on
your example is "administrator" but how would I get that
by using code? I'm new to this VBA stuff...

The normal template is saved in each staff members
personal drive (P:\). The personal drives are named
\\alchemy\private\(username) but I am unsure how to get
that username...

I appreciate your help.. Thanks
 
D

dz

Are you saying that the users' normal templates are not
saved at all on their hard drives?

Would you humor me by running the following code and then
letting me know what comes up?

msgbox Application.NormalTemplate.Path

The username to the answer above should match what is on
your mapped P: drive. Please verify.

Let's do this for awhile through email, as it's a little
tough to drill down to find this thread again. Then we'll
paste the answer once complete.

add cox.net to zivd@ for my email address.

Denise
 

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