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 / July 2005

Tip: Looking for answers? Try searching our database.

User name in File Path

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve C - 14 Jul 2005 22:47 GMT
I am trying to write some code in Word where upon opening a certain template,
the user is prompted with an InputBox asking for his/her Windows login name,
such as "jsmith".  I then want the user name to become part of a file path in
another line of code, as in the following example:

Dim MyName As String

MyName = InputBox ("Please enter your user name")

...Destination:= "C:\Documents and Settings\MyName\Application
Data\Microsoft\Templates\Normal.dot"

How do I write the file path so that MyName becomes part of the file path?  
Thanks!

Steve C
Doug Robbins - 14 Jul 2005 23:02 GMT
Destination:= "C:\Documents and Settings\" & MyName & "\Application
Data\Microsoft\Templates\Normal.dot"

But, see the article "How to get the username of the current user" at:

http://word.mvps.org/FAQs/MacrosVBA/GetCurUserName.htm

and dispense with the need for the inputbox.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I am trying to write some code in Word where upon opening a certain
>template,
[quoted text clipped - 15 lines]
>
> Steve C
Steve Yandl - 15 Jul 2005 00:10 GMT
An alternate approach to extract the user's name which also avoids the input
box.

Set nwObj = CreateObject("WScript.Network")
strUser = nwObj.UserName

Steve

> Destination:= "C:\Documents and Settings\" & MyName & "\Application
> Data\Microsoft\Templates\Normal.dot"
[quoted text clipped - 25 lines]
>>
>> Steve C
Steve Yandl - 15 Jul 2005 00:42 GMT
Not any simpler but this is a second approach that uses the
shell.application to return the path to the local user's Application Data
folder.

Set objShell = CreateObject("Shell.Application")
Set objLocAppFldr = objShell.Namespace(&H1C&)
strLocAppFldrPath = objLocAppFldr.Self.Path
strFullPath = strLocAppFldrPath & "\Microsoft\Templates\Normal.dot"

Steve

> Destination:= "C:\Documents and Settings\" & MyName & "\Application
> Data\Microsoft\Templates\Normal.dot"
[quoted text clipped - 25 lines]
>>
>> Steve C
Steve C - 15 Jul 2005 15:28 GMT
Thanks Doug and Steve for all your help!

> Not any simpler but this is a second approach that uses the
> shell.application to return the path to the local user's Application Data
[quoted text clipped - 36 lines]
> >>
> >> Steve C
 
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.