Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
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 -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org 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. |
#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. |
#4
![]() |
|||
|
|||
![]() Quote:
thanks you so much for all the tips and answers..it so great to be here..i easily find answers for my word issues..thanks a lot |
#5
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Wow, this is complex. I was able to follow your instructions and I was able
to have to macro return a result. It does not return the correct email address though. It returns the X400 email and what groups i belong to, not the smtp email address. I could not get the ini file instructions to work without an error. |
#6
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Correction: I was able to to get it to work using the ini file. I really like
this now. I just have to customized it to return to the correct result. Thank you. "Peter L" wrote: Wow, this is complex. I was able to follow your instructions and I was able to have to macro return a result. It does not return the correct email address though. It returns the X400 email and what groups i belong to, not the smtp email address. I could not get the ini file instructions to work without an error. |
Reply |
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 |