OL2000 Function to build Word Docs 
Author Message
 OL2000 Function to build Word Docs

I have a function that will take selected contacts in a selected folder and
build Word Docs based on Contact info and Document Properties.

The problem is that for every contact a new Word doc is generated.  Fine for
2 or 3 contacts but for multiples it gets out of hand fast.  Any ideas on
how I can modify this to append all the word docs into the first one?

I have included a streamlined version of the code below.

Post to Newsgroup or email me.

Thanks,

Teo

Function BuildDocs(strWordTemplate As String)

   Dim nms As NameSpace
   Dim fld As MAPIFolder
   Dim exp As Explorer
   Dim sel As Outlook.Selection
   Dim appWord As Word.Application
   Dim fso As FileSystemObject
   Dim prps As Object
   Dim objItem As ContactItem

   'Set a reference to the selected folder
   Set nms = Application.GetNamespace("MAPI")
   Set exp = Application.ActiveExplorer
   Set sel = exp.Selection

   'Open Word
   Set appWord = GetObject(, "Word.Application")

   For Each objItem In sel
      If objItem.Class = olContact Then
        'Open a new letter based on the selected template
         appWord.Documents.Add strWordTemplate
         appWord.Visible = True

        'Write info from contact item to Word custom doc properties,
        Set prps = appWord.ActiveDocument.CustomDocumentProperties
        With prps
            .Item("FullName").Value = objItem.FullName
            .Item("FullAddress_home").Value = objItem.HomeAddress
        End With
        appWord.ActiveDocument.Fields.Update
        appWord.Activate
      End If

NextItem:
   Next objItem

End Function



Sat, 31 May 2003 21:50:17 GMT  
 OL2000 Function to build Word Docs
Hi Teo,

Quote:
> The problem is that for every contact a new Word doc is generated.  Fine for
> 2 or 3 contacts but for multiples it gets out of hand fast.  Any ideas on
> how I can modify this to append all the word docs into the first one?

Take a look at the InsertFile method, see if that does what you need? You can
insert a page break or a next page type of section break between the
recipient's documents, if you need that.

However, have you considered using Tools/Mail Merge from within Outlook?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)



Sat, 31 May 2003 23:34:09 GMT  
 OL2000 Function to build Word Docs
Thanks Cindy!

I will check that out, it seems like a good idea.

I can use the Tools / Mail Merge but it is flaky at best.  I have several
contacts and very long documents that need much customizing.  Using mail
merge tends to lock up my PCs.   This is much easier and a little time
coding it now saves time in the end.

Teo


Quote:
> Hi Teo,

> > The problem is that for every contact a new Word doc is generated.  Fine
for
> > 2 or 3 contacts but for multiples it gets out of hand fast.  Any ideas
on
> > how I can modify this to append all the word docs into the first one?

> Take a look at the InsertFile method, see if that does what you need? You
can
> insert a page break or a next page type of section break between the
> recipient's documents, if you need that.

> However, have you considered using Tools/Mail Merge from within Outlook?

> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister
> http://www.mvps.org/word
> http://go.compuserve.com/MSOfficeForum

> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)



Mon, 02 Jun 2003 05:30:12 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Word's built in functions

2. Convert Word docs to Word forms??

3. Need OCX for viewing Word Docs without Word

4. Merge & print Word docs without Word

5. Finding text inside Word Docs without using Word

6. Finding text inside Word Docs without using Word

7. VB5 HARD ONE:Locking Word OLE session to other Word Docs

8. Finding text inside Word Docs without using Word

9. Word docs remain open in background after VB code

10. Help with linked Word Docs

11. Linking an existing Word docs into Access reports

12. Importing Word Docs into Access

 

 
Powered by phpBB® Forum Software