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 / Mailmerge and Fax / February 2005

Tip: Looking for answers? Try searching our database.

Add code to select email field in mailmerge!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hans - 01 Feb 2005 06:43 GMT
Is it possible to add a macro inside a dot file than when doing a mailmerge
will select the correct email field so the user don't have to select which
is the email field manually? I have a program that generates a tab separated
text file with data and opens the dot file and do the actual mailmerge.

What is missing is the automation to send the emails and this also includes
selecting which field is the email address (for my template I know which
field contains the email address).

Ideally a solution working for Win2000 and higher would be best but if there
are functionality in office XP or 2003 that makes this task easier please
let me know.

Regards
/Hans
Doug Robbins - 01 Feb 2005 11:14 GMT
Here's a Macro to extract all of the email addresses from a document, but
you would probably be better off to modify the technique used in the article
"Mail Merge to E-mail with Attachments" at

http://word.mvps.org/FAQs/MailMerge/MergeWithAttachments.htm

Sub CopyAddressesToOtherDoc()

  Dim Source As Document, Target As Document, myRange As Range
   Set Source = ActiveDocument
   Set Target = Documents.Add

Application.ScreenUpdating = False

   Source.Activate
   Selection.HomeKey Unit:=wdStory
   Selection.Find.ClearFormatting
   With Selection.Find
Do While .Execute(findText:="[+0-9A-z._-]{1,}\@[A-z.]{1,}", _
MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True
           Set myRange = Selection.Range
           Target.Range.InsertAfter myRange & vbCr
       Loop
   End With

Selection.HomeKey Unit:=wdStory
Target.Activate

End Sub

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Is it possible to add a macro inside a dot file than when doing a
> mailmerge
[quoted text clipped - 15 lines]
> Regards
> /Hans
Hans - 01 Feb 2005 12:06 GMT
Thanks Doug for your help but I think I was unclear what I want to do.

I have an application that creates a tab separated file (lets call this
data.txt) where one column contains the email address. The application opens
the template file and the template reads the data.txt file. If they want to
mail this document they can click the "Merge to Email" button but then you
would have to select which field is the email field. I wonder if it is
possible to add macro code so they don't need to click on the "Merge to
Email" button where you manually have to select the email field, enter a
subject and click OK). Ideally it should

1. select the correct email field automatically (I know the name of the
column that contains the email address )

2. Set a subject (ideally they would like to have dynamic merge instructions
in the subject as well to customize the subject line for every email. For
example add the contact name which is also part of the data.txt file. Is it
possible to have mailmerge instructions in the subject?)

3. Do the actual send.

Either this could be executed in an event (open) or maybe a button could be
created that will do step 1-3 automatically. I know this sounds silly but
they think 3-4 clicks is too much to do. They want single click
functionality.

I guess I can solve this by following the steps in the URL you sent but it
seems to be overkill in this case.

Regards
/Hans

P.s Sorry for my english but I guess it is better than your swedish :-) D.s
Doug Robbins - 01 Feb 2005 23:38 GMT
I understood exactly what you want to do and the information that I posted
should give you a few ideas about how to go about it.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Thanks Doug for your help but I think I was unclear what I want to do.
>
[quoted text clipped - 35 lines]
> P.s Sorry for my english but I guess it is better than your swedish :-)
> D.s
Hans - 03 Feb 2005 06:47 GMT
Hi Doug!

Ok I guess I will have to look deeper into your example. I was hoping this
was a three line macro. The dialog where you select the field containing the
email addrss, setting the subject and then send the emails looks like two
property settings to me and one call to a method send so I was hoping it was
possible to set these programtically (the properties and method below don't
exist but I was hoping that they do exist but maybe with another name).

Mydocument.active_email_property =
"<my_mailmerge_field_containing_email_address>"
Mydocument.subject_for_email = "Some subject"
Mydocument.send

Thanks for your help!
Regards
/Hans
 
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.