Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail Merge from VB6 to Word 2003

Status
Not open for further replies.

mcs1000

Programmer
Jul 3, 2007
26
GB
Can I automate a mail merge from VB6 to Word 2003 without opening word?
 
I would write the data to a text file then do the mailmerge with code like this

Code:
Dim wdapp3 As Word.Application
Dim WdNewDoc3 As Word.Document
                    
Set wdapp3 = CreateObject("Word.Application")
Set WdNewDoc3 = CreateObject("Word.Document")
                                                            
                           wdapp3.Documents.Open "C:\Program Files\IMS\Invoice_Batch.doc", _
ConfirmConversions:=False, ReadOnly:=True, AddToRecentFiles:=False, _
PasswordDocument:="HERE", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:=wdOpenFormatAuto, _
Visible:=True
                   
wdapp3.ActiveDocument.MailMerge.Execute (True)
Set WdNewDoc3 = wdapp3.ActiveDocument
wdapp3.Documents(2).Close savechanges:=wdDoNotSaveChanges
wdapp3.Visible = True
wdapp3.Activate
                    
Set wdapp3 = Nothing
Set WdNewDoc3 = Nothing

[code]

But its also well to note this:

[URL unfurl="true"]http://support.microsoft.com/kb/825765[/URL]
(security bypass for Word 2003)

and this

[URL unfurl="true"]http://support.microsoft.com/kb/290981[/URL]
(set a default encoding)

So you will have to change the registry on each PC.  I have done this austomatically with:

[code]

Public Function UpdateReg()

Const HKEY_CURRENT_USER = &H80000001

Dim strcomputer As String
Dim objRegistry As Object
Dim strKeyPath As String
Dim strValueName As String
Dim dwValue As String


strcomputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strcomputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Office\11.0\Word\Options"
    

'[URL unfurl="true"]http://support.microsoft.com/kb/290981[/URL] Word 2003 error for Txt encoding for MM
    strValueName = "DefaultCPG"
    dwValue = 1252
    objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue

'[URL unfurl="true"]http://support.microsoft.com/kb/825765[/URL] Word 2003 security check remover
    strValueName = "SQLSecurityCheck"
    dwValue = 0
    objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue


End Function

[\code]

Obviously this code is untested, and you should probably look into the implications of the registry entries before you do them

Dan

----------------------------------------
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
Cheers Plank,

That's good stuff.

I'll give a whirl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top