|
-
Jul 6th, 2009, 05:04 AM
#1
Thread Starter
Hyperactive Member
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
-
Jul 6th, 2009, 06:50 AM
#2
Re: Word automation
see the tutorial in the faq at the top of the forum
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 8th, 2009, 01:52 AM
#3
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 8th, 2009, 03:44 AM
#4
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?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 9th, 2009, 05:30 AM
#5
Thread Starter
Hyperactive Member
Re: Word automation
Rob,
thanks for your help on this, i will take a proper look later once i get 5 minutes.
David
-
Jul 20th, 2009, 09:19 AM
#6
Thread Starter
Hyperactive Member
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
Last edited by Davadvice; Jul 20th, 2009 at 09:30 AM.
This is Blank
-
Jul 20th, 2009, 12:30 PM
#7
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 21st, 2009, 06:02 AM
#8
Thread Starter
Hyperactive Member
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
-
Feb 1st, 2010, 01:54 PM
#9
Addicted Member
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|