|
-
May 23rd, 2005, 10:42 AM
#1
Thread Starter
New Member
VBA for Word - Noob needs some assistance.
I have been punted the task of creating a macro for distribution that will append <Signature:USERNAME> to a word document.
USERNAME = Current logged on user.
I have no clue what variable to use for enumerating the current logged on user in VBA.
I have been playing with various things, but due to my lack of experience with VB I have had no success.
Sub NewMacros()
Selection.TypeText Text:="<Signature:Environment.UserName>"
End Sub
I am a little familiar with WSH, but have never done anything with VBA, so any assistance would be appreciated.
-
May 23rd, 2005, 11:26 AM
#2
Frenzied Member
Re: VBA for Word - Noob needs some assistance.
Not sure if word has this, but Excel has Application.UserName, which returns the name of the person using Excel, or whoever it's registered to if they don't have to log in somehow.
To get the user name of the person logged on to the computer, use the GetUserName API. This will work in any version of VB up to and possibly including .Net, although there you can use Environment.UserName more easily. This will be their logon name, so if they log on as "smith.j" that's what you'll get.
Tengo mas preguntas que contestas
-
May 24th, 2005, 03:04 PM
#3
Thread Starter
New Member
Re: VBA for Word - Noob needs some assistance.
Thanks. I will check this out.
-
May 25th, 2005, 02:55 PM
#4
Thread Starter
New Member
Re: Appending user name Text string in Word Document
Thanks for any assistance on this. Here is the functioning code for the future. This code will append the following text to any word document.
<SIGNATURE:DOMAIN USERNAME>
This code is intended to append a signature to a word document in conjunction with RIghtFax.
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Sub main()
Dim str As String
Dim result As Long
result = 0
str = Space(1000)
result = GetUserName(str, Len(str))
result = Len(Trim(str))
str = Left(str, Len(Trim(str)) - 1)
'ActiveDocument.Select - Uncomment this only to replace all text in document
Selection.Text = "<SIGNATURE:" + str + ">"
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|