Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

%userprofile% How to Access this Value

Status
Not open for further replies.

logout151

IS-IT--Management
Nov 15, 2000
24
US
While converting some excel macro's (involving templates) to w2k I came across this problem. W2k does stores the templates in the local user directory. Which is used %userprofile% . How can I get VB to pick up this value? and write to the correct directory depending on who's logged on? The old way (win95) was easy, as the path did not change for templates. Now I can't get VB to recognize the user.

Any help?

-Log
 
Application.TemplatesPath 'Returns the local path where templates are stored. Read-only String.

Application.DefaultFilePath 'the path you are looking for, i presume
'Returns or sets the default path that Microsoft Excel uses when it opens files.

Application.LibraryPath 'Returns the path to the Library folder, but without the final separator.

Application.StartupPath 'Returns the complete path of the startup folder, excluding the final separator.

Application.UserLibraryPath 'Returns the path to the location on the user’s computer where the COM add-ins are installed.

or API:
'*****************
GetDefaultUserProfileDirectory
Declare Function GetDefaultUserProfileDirectory Lib "userenv.dll" Alias "GetDefaultUserProfileDirectoryA" (ByVal lpProfileDir As String, lpcchSize As Long) As Boolean
sub dd()
Dim sBuffer As String
sBuffer = String(255, 0)

'retrieve the user profile directory
GetDefaultUserProfileDirectory sBuffer, 255
end sub
'*****************
Private Declare Function GetAllUsersProfileDirectory Lib "userenv.dll" Alias "GetAllUsersProfileDirectoryA" (ByVal lpProfileDir As String, lpcchSize As Long) As Boolean
sub dd2()
Dim sBuffer As String
sBuffer = String(255, 0)
'retrieve the all users profile directory
GetAllUsersProfileDirectory sBuffer, 255
'show the result
Me.Print StripTerminator(sBuffer)

end sub

'strips off the trailing Chr$(0)'s
Function StripTerminator(sInput As String) As String
Dim ZeroPos As Long
ZeroPos = InStr(1, sInput, Chr$(0))
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function

'*****************

...i tak dalse
:)
ide
 
Thanks for you answer, it will definetly help.

While researching this, I came across the function ENVIRON which gives the values for 27 environmental variables. You can just plug them in when needed.

Thanks Again.

This will list them all for you, I figured I would save you or anybody else the typing since I had it already.


Dim i As Integer

For i = 1 To 27
Debug.Print i & ") " & Environ(i)
Next i

:) Log
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top