-
Word automation
hi,
I'm looking to automate word to allow users to send letters to customers. i am using access 2k and work 2k.
I have automated excel and outlook functions with VBA before however i have never done anything with word.
Is it worth while using word for the task, i have seen word automated previously and it always seemed to fail and the code looked gastly. i do have to say the guy the coded it was not know for best practice.
I have a mege document and only need to use 5 items from a dataset.
is there an easy way to run the mailmerge using VBA ? does anyone have any good tut's on the subject ?
thanks in advance
David
-
Re: Word automation
see the tutorial in the faq at the top of the forum
-
Re: Word automation
Basic Word Mailmerge setup:
http://www.vbforums.com/showthread.php?t=402097
I have another thread where I get into the automation of the mailmerge sql and invoking etc. I'll look for it.
-
Re: Word automation
I couldnt find it so I wrote up a basic FAQ on executing the mailmerge from VB6 but its the same code for from within Access.
How do I execute a Word MailMerge document?
-
Re: Word automation
Rob,
thanks for your help on this, i will take a proper look later once i get 5 minutes.
David
-
Re: Word automation
Rob,
Thanks for the code above, worked a treat for the most part.
I have one issue, when I open my Datasource (an MDB file) the database window is being left open after the print job has completed and all the word objects are closed and destroyed.
The issue I have is that the application name for the datasource and the application initiating the mail merge are the same and if I close it using an API call then it may close the access session that I wish to leave open. Do you know if there is a way to alter the merge properties to prevent it showing the source?
edit:I'm looking down the ODBC route now see if i can get round it that way.
Thanks for your help
David
-
Re: Word automation
So you are wanting to close and quit access after word prints? If so then try..
Application.CloseCurrentDatabase
Application.Quit
Application will refer to your Access application
-
Re: Word automation
hi Rob,
Not the instance of access running the process but the access db instance that is used for the datasource.
for instance when i open the main app "debt manager" i navigate to the form for reporting
I select the mailmerge item from a Combo and click run reports. this then opens a new instance of the Debt manager Application (to get the source for the mail merge) and it is this instance (the second instance) i want to close.
it's not very clear i know sorry if you don't get what i'm saying.
thanks
David
-
Re: Word automation
If I can borrow this thread:
When I create a Word macro to create an Outlook item, I just couldnt have several words after & (only the next one) in the subject field
example:
.Subject = "Open file, " & Kon1 & " " & Rapn
This results in only (in the subject field): Open file, BlaForKon1
What I am trying to tell is that nothing after Kon1 is in the subject field when the email is created.
But when I macro in outlook to create an email item everything is included.
Why is there a problem with this in Word? How can I include more than one string in the subject field after the &:s (and)?
See the full code of email item:
Code:
Dim OutlookMessage As Object
Set OutlookMessage = CreateObject("Outlook.application").createitem(0)
With OutlookMessage
.Subject = "Open file " & Kon1 & " " & Rapn
.body = Wordtext
.to = "SUES"
.SentOnBehalfOfName = "SUES"
.HTMLBody = mailBody
.Display
End With
Set OutlookMessage = Nothing
Best Regards
Groom