Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Trying to keep things as simple as possible the following stores the user
details in an ini file in the user templates folder. The first time the macro is run it will prompt for the user details. These are then stored and used to insert the data subsequently. The macro uses a message box to confirm the details are correct and thus allows the user to change incorrect details. You can save this as an autonew macro in the fax document template or add it to a toolbar button. Dim SettingsFile As String Dim sUserName As String Dim sEmail As String Dim sTitle As String Dim sCheck As String On Error Resume Next SettingsFile = Options.DefaultFilePath(wdUserTemplatesPath) & "\Settings.ini" sUserName = System.PrivateProfileString(SettingsFile, _ "ThisUser", "Name") sEmail = System.PrivateProfileString(SettingsFile, _ "ThisUser", "Email") sTitle = System.PrivateProfileString(SettingsFile, _ "ThisUser", "Title") If sUserName = "" Then GetUser: sUserName = InputBox("Enter user's Name", "User Name", sUserName) sTitle = InputBox("Enter user's title, if any", "User Title", sTitle) sEmail = InputBox("Enter user's e-mail address", "User E-mail", sEmail) System.PrivateProfileString(SettingsFile, "ThisUser", _ "Name") = sUserName System.PrivateProfileString(SettingsFile, "ThisUser", _ "Email") = sEmail System.PrivateProfileString(SettingsFile, "ThisUser", _ "Title") = sTitle End If sCheck = MsgBox("User is " & sUserName & vbCr & sTitle & _ vbCr & sEmail, vbYesNo, "Confirm User Details") If sCheck = vbNo Then GoTo GetUser: With Selection .GoTo What:=wdGoToBookmark, name:="EMail" .TypeText Text:=sUserName & vbTab & sEmail & vbCr & sTitle End With -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Graham Mayor wrote: I take it that you want this template to apply to whoever uses it rather than for your personal use? The following macro will read and enter the current user's name and e-mail address from Outlook at a bookmark location "Email" or at the cursor if that location does not exist. You will need to add the Outlook object library to the vba editor tools references. Sub InsertCurrentUsersEmailAddress() Dim olook As Outlook.Application Dim sEAddress As String Dim sEName As String Dim bStarted As Boolean On Error Resume Next Set olook = GetObject(, "Outlook.Application") If Err 0 Then Set olook = CreateObject("Outlook.Application") bStarted = True End If sEAddress = olook.Session.CurrentUser.Address sEName = olook.Session.CurrentUser.name ' Close Outlook if it was started by this macro. If bStarted Then oOutlookApp.Quit End If With Selection .GoTo What:=wdGoToBookmark, name:="EMail" .TypeText Text:=sEName & vbTab & sEAddress End With End Sub http://www.gmayor.com/installing_macro.htm Obtaining the title is rather more complicated as the user's title is not stored in Word or Outlook. I suppose it would be possible to write code to populate custom document property fields and read those into the document, but it all starts to get a tad complicated if the template is to be shared. See also http://www.gmayor.com/Macrobutton.htm Peter L wrote: In word 2007, I am trying to create a fax cover sheet template that will auto-populate the user's name, title and email address as soon as they open the template. I know how to insert today's date but i cannot figure out how to have the user's email address get filled in the template as soon as it opens. |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
how do i remove auto popup in the email address bar for ? | Microsoft Word Help | |||
Auto Populate | Microsoft Word Help | |||
E-mail Addresses Auto-populate in Word | Microsoft Word Help | |||
how do I remove an email address from Auto Text in Word? | Microsoft Word Help | |||
how do i auto-populate tables in word? | Tables |