GetUserName Differences between VB6 & VBA

R

Roger

I have a program which used the following code to retrieve the user's
id from the system;

Private Declare Function GetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetUserNameText() As String
Dim strReturn As String
Dim intLength As Long

strReturn = String(1024, 0)
intLength = Len(strReturn)
If GetUserName(strReturn, intLength) <> 0 Then
GetUserNameText = Left(strReturn, intLength - 1)
End If
End Function

I then use this variable (GetUserNameText) in a path to locate files
etc;
"D:\DATA\" & GetUserNameText & "\Cognos\CD TDT Sales....xls

This code works fine in a VB6 application that I have build, but when
transferring this into Excel 97 it does not find the path.

Does anyone know of any reasons why this would happen, are there
reasons which would prevent this from working?

Your help is appreciated.

Roger..
 
H

Howard Kaikow

You do not give the code for finding the path.

I suspect the code is not the same for your VB 6 and VBA code.

Since there may be spaces in the path specification, you may need to make
sure that the path is enclosed in quote characters before passing to the
file system code.
 

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