Application.Username error in Word 2007

K

Karen

Hi All, I use application.username in an If statement to determine who might
be running some code and therefore what directory structure templates are
stored in. This has always worked fine, until now in Word 2007 I SOMETIMES
get the error Runtime error 5174 - This file could not be found.

Even the code:

Msgbox Application.Username

will give this error.

Can anyone shed any light on the issue?
 
M

Manfred F

Hi Karen,

Karen said:
Hi All, I use application.username in an If statement to determine who might
be running some code and therefore what directory structure templates are
stored in. This has always worked fine, until now in Word 2007 I SOMETIMES
get the error Runtime error 5174 - This file could not be found.

I've also had problems accessing the Application.UserAddress. Sometimes it
is not accessible, not even readable. I had to put a workaround into my code.
As a workaround, You could determine the username via API functions.. ?

Kind Regards,
Manfred
 
K

Karen

Hi Manfred, unfortunately I don't know how to use API functions.
Currently I use:

If Application.Username = "Karen" or Application.Username = "Judith" then
(I set my default file locations here)
End If

How would an API function work in this case?
 
M

Manfred F

Hi Karen

Karen said:
Hi Manfred, unfortunately I don't know how to use API functions.

You can find them when You search the word discussion sites on the web.
The following code gives me the OS's username for Word 2003:

Private Declare Function apiGetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nsize As Long) As Long

Public Function Username_OS() As String
Dim StrLen As Long
Dim ApiResult As Long
Dim WorkStr As String
Dim Result As String

' call API
WorkStr = String$(254, 0)
StrLen = 255
ApiResult = apiGetUserName(WorkStr, StrLen)

' Name found: Result
If (ApiResult <> 0) Then
Result = Left$(WorkStr, StrLen - 1)
End If ' ... name found

Username_OS = Result
End Function ' 'username_os'
 

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