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 / September 2003

Tip: Looking for answers? Try searching our database.

Simple document creation?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Craig Cernek - 27 Sep 2003 15:02 GMT
let me take a giant step back to the basics.

Let's say that I have just completed calling a husband
and wife prospect from Outlook and that I would like to
send them a follow-up letter.

What is the most expeditious [meaning fewest mouse clicks
and keystrokes] manner of creating a standard follow-up
letter, on my company's letterhead, with the current
date, properly addressed to both husband and wife, be
prompted for and have an opportunity to include a re:,
and include an image of my handwritten signature?

When I was using ACT!, I simply created macro buttons to
represent each of the standard document templates that I
would like to create and merge with the currently
highlighted contact.

Once I had highlighted a contact in ACT!, a single mouse
click on the appropriate macro button, along with typing
in the appropriate re: when prompted, created a completed
document.  If I chose to personalize the body of the
text, so be it.

I find that the excessive amount of keystrokes and mouse
clicks [over 22 mouse clicks alone!]of the letter writing
Wizard is both painful [due to RSI and injury] and
unconscionable in this digital day and age!

Now that I am using Outlook, the closest method that I
can determine that is available for doing this is
invoking mail merge for a highlighted contact and
choosing the appropriate document template!

I believe that outlook and word are excessively complex
and can be customized in many ways.  However I do not
have the time to research and learn all of the technical
aspects and possibilities.

Has anyone found a better way, other than mail merge, to
simply do what I was able to do so effortlessly in ACT?

Thank you.
Peter Jamieson - 28 Sep 2003 17:42 GMT
I think you would have to implement something in VBA to improve the current
situation, and the general problems with that are...
a. you have to know how to use VBA and Office Automation to make things
work for you
b. there's a huge difference between writing VBA code that works "if you're
careful", and writing it so it works in all normal scenarios, with all
versions of Word and Outlook
c. if you don't know VBA, it's difficult to know how much time to invest in
a VBA-based solution.

If you decide to go down this route, the following sample code may help. But
a. I don't use, or program, in Outlook much. For the Outlook side of this,
you'll probably get much better help in an Outlook group. There ought to be
better error testing. And so on.
b. it isn't tested in a live scenario and needs some work to make it do
what /you/ want

The overview is that you copy the macros provided below into the Outlook VBA
editor. The text of the macros will probably have wrapped so you will need
to fix that in the editor. You will also need to use Tools|References to
"set a reference" to the Word Object Library, and enable Macros in Outlook.
You will need to modify the macros to suit your requirements, but you should
be able to /test/ them almost as is.

Then, for each new type of letter, you
a. produce a Word document (or preferably a template).
b. use Document property fields to specify where you want the data from
your contact item, in much the same way as you use Mergefield fields in Word
mailmerge operations
c. copy and rename two small macros in Outlook, and change the parameters
(one is the name of the template or pathname of the word document, and the
other is just a "letter category" I've put in there, partly as
documentation. One of the macros is used when you have selected a contact
item in a typical Outlook "Explorer" list. The other is used when you have
opened a Contact for viewing/editing in what Outlook calls an Item
"Inspector"
d. In Outlook, use Tools|Customize to create a toolbar button for the
"explorer" macro. If you want, collect all these buttons on a "Letters"
toolbar. You will probably want to change the properties of the button so
that it is an image and you use the "default style" (which means the button
just shows the image and not the macro name). You could also associate it
with a keystroke.
e. Open a contact in an Inspector. Then use Tools|Customize within the
Inspector to create a toolbar button for the "inspector" macro.

Obviously, you don't have to use both Explorer and Inspector macros - it
depends on how you work.

That's the groundwork. To use it, you either select a contact in a list,
click the appropriate button when you want to create a letter, and provide a
subject, or if you have opened a contact inspector, you click the button in
there and provide a subject. The macros should create/load a document, set
up all the document properties (change the macro code to add the ones you
need), then display the document so you can edit it.

As far as using Document properties fields in Word is concerned, you just
need to add { DOCPROPERTY "property name" } fields where you want the data.
For most if not all the built in properties such as Subject, you can either
use { SUBJECT }, { Docproperty Subject } or { INFO Subject }. Since you can
put any plain text up to a certain size limit into a Document Property, you
can also put stuff such as creation date in them if you want. I've only used
Document Properties because they are almost designed for this kind of use
(you will have a permanent record of the contact info at the time you
created the letter, and can display such info. in e.g. Outlook lists and
Windows Explorer lists. You also have a built-in dialog box to inspect and
modify the properties). Alternatives would be
a. stuff the data directly into the document, based on some "placeholders"
b. use Document Variables.

Here's the code.

Sub ProduceLetter1FromExplorer()
' Macros by Peter Jamieson 28 Sep 2003
' You need one of these macros with a different name for each letter.
 ProduceLetterFromExplorer _
   BaseDocTemplate:="c:\myoldocs\mydoc.doc", _
   Category:="Follow-up 1"
End Sub
Sub ProduceLetter1FromInspector()

' Macros by Peter Jamieson 28 Sep 2003
' You need one of these macros with a different name for each letter.
 ProduceLetterFromInspector _
   BaseDocTemplate:="c:\myoldocs\mydoc.doc", _
   Category:="Follow-up 1"
End Sub

Sub ProduceLetterFromExplorer(BaseDocTemplate As String, Category As String)

' Macros by Peter Jamieson 28 Sep 2003
' General-purpose macro to produce a new letter from the first
' item selected in an Outlook Explorer
With Application.ActiveExplorer.Selection
 If .Count = 0 Then
   MsgBox "No items selected"
 Else
   ' this routine just uses the first of the selected items
   ' if you want to generate docs for /all/ of the selected items
   ' you will probably make things very confusing for the user

   ' Make sure it is a Contact Item. I think user-defined Contact
   ' item class names probably also start with "IPM.Contact" so
   ' just check the first 11 characters
   If Left(.Item(1).MessageClass, 11) <> "IPM.Contact" Then
     MsgBox "The first selected item is not a Contact item"
   Else
     ProduceLetter BaseDocTemplate:=BaseDocTemplate, Category:=Category,
CItem:=.Item(1)
   End If
 End If
End With
End Sub

Sub ProduceLetterFromInspector(BaseDocTemplate As String, Category As
String)

' Macros by Peter Jamieson 28 Sep 2003
' General-purpose macro to produce a new letter from a
' contact item opened in an Outlook Explorer
With Application.ActiveInspector

 ' Make sure it is a Contact Item. I think user-defined Contact
 ' item class names probably also start with "IPM.Contact" so
 ' just check the first 11 characters
 If Left(.CurrentItem.MessageClass, 11) <> "IPM.Contact" Then
   MsgBox "The item is not a Contact"
 Else
     ProduceLetter BaseDocTemplate:=BaseDocTemplate, Category:=Category,
CItem:=.CurrentItem
 End If
End With
End Sub

Sub ProduceLetter(BaseDocTemplate As String, Category As String, CItem As
Object)
' Macros by Peter Jamieson 28 Sep 2003
' General-purpose macro to produce a new letter from the contact item in
CItem

Dim oContact As Outlook.ContactItem
Dim oWord As Word.Application
Dim oDoc As Word.Document
' The following do not appear to work if we define them
' as Office.DocumentProperties
Dim oBuiltinProperties As Object
Dim oCustomProperties As Object
Dim r As Word.Range
Dim f As Word.Field
Dim strSalutation As String
Dim strAddress As String
Dim strSubject As String

' now ask for the subject line you want to use in the document
' use this as an opportunity to cancel by leaving the field blank
' if you want to prompt for more fields, create a userform instead
strSubject = InputBox("Enter the subject, or leave it blank to cancel")
If Trim(strSubject) <> "" Then
 Set oContact = CItem

 ' try to reuse any existing instance of Word
 On Error Resume Next
 Set oWord = GetObject(, "Word.Application")
 If Err.Number <> 0 Then
   MsgBox Err.Number & " " & Err.Description
   Err.Clear
   On Error GoTo 0
   Set oWord = CreateObject("Word.Application")
 End If

 ' In theory we should check first that the document
 ' is not alredy open

 ' You could use a document or a template. Assume we
 ' can use the extension to work out which it is
 ' you will also need to add a bit of code (certainly for
 ' the .DOC case) to save the document under a new name,
 ' preferably immediately
 If UCase(Right(Trim(BaseDocTemplate), 3)) = "DOC" Then
   Set oDoc = oWord.Documents.Open(BaseDocTemplate)
 Else
   Set oDoc = oWord.Documents.Add(BaseDocTemplate)
 End If
 Set oBuiltinProperties = oDoc.BuiltInDocumentProperties
 ' Broadly speaking, you can assign whatever you want to
 ' either a Builtin Property or a Custom Property, and
 ' you can call the custom properties whatever you want,
 ' as long as you avoid clashes,
 ' but it probably makes sense to use the established names
 ' where possible
 oBuiltinProperties("Subject").Value = strSubject
 oBuiltinProperties("Category").Value = Category
 oBuiltinProperties("Keywords").Value = oContact.Categories
 Set oBuiltinProperties = Nothing
 ' You can either construct names, salutations & addresses
 ' here or using Word fields. However, it is probably better
 ' to do it here or you have to mess arund with Word IF fields
 ' and so on.

 ' You might also want to define some more parameters
 ' for this routine, e.g. to say "for this letter I want
 ' the person's name and business address, for this one
 ' I want the Mr and Mrs + home address" and so on.

 ' Only you know exactly what you need, but here is an example
 ' which assumes we use a Home address in US format, with no
 ' country name, and various other things about surnames and
 ' what you store in the Spouse field.

 strSalutation = Trim(oContact.FirstName)
 If Trim(oContact.Spouse) <> "" Then
   strSalutation = strSalutation & " and " & Trim(oContact.Spouse)
 End If
 strAddress = strSalutation & " " & oContact.LastName & vbCrLf & _
              oContact.HomeAddressStreet & vbCrLf & _
              oContact.HomeAddressCity & ", " & _
              oContact.HomeAddressState & " " & _
              oContact.HomeAddressPostalCode
 strSalutation = "Dear " & strSalutation
 Set oCustomProperties = oDoc.CustomDocumentProperties
 On Error Resume Next
 oCustomProperties("Salutation").Delete
 oCustomProperties("Address").Delete
 Err.Clear
 On Error GoTo 0
 oCustomProperties.Add _
   Name:="Salutation", _
   LinkToContent:=False, _
   Type:=msoPropertyTypeString, _
   Value:=strSalutation
 oCustomProperties.Add _
   Name:="Address", _
   LinkToContent:=False, _
   Type:=msoPropertyTypeString, _
   Value:=strAddress
 Set oCustomProperties = Nothing
 ' notice also that you will be unable to get data concerning
 ' the email addresses in more recent versions of Outlook
 ' without seeing the "security dialog"

 ' Update all the fields in the document
 ' unlink all the Document Property fields
 For Each r In oDoc.StoryRanges
   r.Fields.Update
   ' optionally unlink all the docproperty fields
   ' For Each f In r.Fields
   '   If f.Type = wdFieldDocProperty Then
   '     f.Unlink
   '   End If
   ' Next
 Next
 ' You can do these further up if you like to see what is going on
 oWord.Visible = True
 oWord.Activate

 Set oDoc = Nothing
 Set oWord = Nothing
 Set oContact = Nothing
End If
End Sub

--
Peter Jamieson
MS Word MVP

> let me take a giant step back to the basics.
>
[quoted text clipped - 39 lines]
>
> Thank you.
Craig Cernek - 29 Sep 2003 00:23 GMT
Thank you.

It will take me a while to understand your responce.
>-----Original Message-----
>I think you would have to implement something in VBA to improve the current
[quoted text clipped - 134 lines]
>' Macros by Peter Jamieson 28 Sep 2003
>' General-purpose macro to produce a new letter from the
contact item in
>CItem
>
[quoted text clipped - 168 lines]
>
>.
 
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.