Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Peter L Peter L is offline
external usenet poster
 
Posts: 1
Default Auto-Populate Email Address in Word 2007

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   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Auto-Populate Email Address in Word 2007

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   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Auto-Populate Email Address in Word 2007

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   Report Post  
mye01 mye01 is offline
Junior Member
 
Posts: 0
Thumbs up

Quote:
Originally Posted by Graham Mayor View Post
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.

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   Report Post  
Posted to microsoft.public.word.docmanagement
Peter L[_2_] Peter L[_2_] is offline
external usenet poster
 
Posts: 2
Default Auto-Populate Email Address in Word 2007

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   Report Post  
Posted to microsoft.public.word.docmanagement
Peter L[_2_] Peter L[_2_] is offline
external usenet poster
 
Posts: 2
Default Auto-Populate Email Address in Word 2007

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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i remove auto popup in the email address bar for ? Chaos1963 Microsoft Word Help 1 April 3rd 08 03:13 AM
Auto Populate Andy Microsoft Word Help 4 March 10th 08 11:46 PM
E-mail Addresses Auto-populate in Word Kat Q. Microsoft Word Help 1 October 29th 07 03:28 PM
how do I remove an email address from Auto Text in Word? ingin Microsoft Word Help 3 April 14th 06 06:51 AM
how do i auto-populate tables in word? RemySS Tables 1 August 4th 05 11:35 AM


All times are GMT +1. The time now is 04:53 AM.

Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"