If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Call Word Mail Merge macro from Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-10-11, 18:11
lucy68 lucy68 is offline
Registered User
 
Join Date: May 2009
Posts: 20
Call Word Mail Merge macro from Excel

I have Googled this extensively and see that lots of people are having the same problem.

I am trying to call a Word macro that runs a mail merge (The data source is in Access) from Excel to save my users a bunch of confusing steps and am getting the following error:

Run-time error '4605':

This method or property is not available because the document is not a mail merge main document.



Excel macro:

Sub runwordmacro()

Set WD = CreateObject("word.application")

WD.Application.documents.Open "K:\Software\Dynamics\Automate JEs\Automatic Journal Entry Import.docm"
WD.Application.Visible = True
WD.Application****n "PayrollJE"
Set WD = Nothing

End Sub

Word macro:

Sub PayrollJE()
'
' PayrollJE Macro
'
'' Open the Mail Merge Template and execute the Mail Merge.
Dim objWord As Word.Document
Set objWord = GetObject("K:\Software\Dynamics\Automate JEs\JE Import Mail Merge Template - Payroll.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
Application.DisplayAlerts = wdAlertsNone
SubType = wdMergeSubTypeWord2000
'
' Execute the mail merge.
objWord.MailMerge.Execute
'
'Insert Header and Footer
'
Selection.TypeText Text:="# DEXVERSION=10.0.320.0 2 2"
Selection.TypeParagraph
Selection.TypeText Text:= _
" CommandExec dictionary 'default' form 'Command_Financial' command 'GL_Transaction_Entry'"
Selection.TypeParagraph
Selection.TypeText Text:= _
"NewActiveWin dictionary 'default' form 'GL_Transaction_Entry' window 'GL_Transaction_Entry'"
Selection.TypeParagraph
Selection.TypeText Text:= _
"WindowMove dictionary 'default' form 'GL_Transaction_Entry' window 'GL_Transaction_Entry' pointh 283 pointv -137"
Selection.TypeParagraph
Selection.TypeText Text:= _
"WindowSize dictionary 'default' form 'GL_Transaction_Entry' window 'GL_Transaction_Entry' pointh 562 pointv 979"
Selection.TypeParagraph
Selection.EndKey Unit:=wdStory
Selection.TypeText Text:= _
"ActivateWindow dictionary 'default' form sheLL window sheLL"
Selection.TypeParagraph
'
'Save the merged documant as a Plain Text file with a .mac extensionWord document
'
ChangeFileOpenDirectory "K:\Software\Dynamics\Automate JEs\"
ActiveDocument.SaveAs FileName:= _
"K:\Software\Dynamics\Automate JEs\ImportJE.mac", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF
ActiveDocument.Close
'
'Close Mail Merge document
Windows("JE Import Mail Merge Template - Payroll.doc [Compatibility Mode]").Activate
ActiveDocument.Close
'
End Sub

Sub PayrollBatches()
'
' PayrollBatches Macro
'
' Open the Mail Merge Template and execute the Mail Merge.
Dim objWord As Word.Document
Set objWord = GetObject("K:\Software\Dynamics\Automate JEs\JE Import Mail Merge Template - Batches.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
Application.DisplayAlerts = wdAlertsNone
SubType = wdMergeSubTypeWord2000
'
' Execute the mail merge.
objWord.MailMerge.Execute
'
'Insert Header and Footer
'
Selection.TypeText Text:="# DEXVERSION=10.0.320.0 2 2"
Selection.TypeParagraph
Selection.TypeText Text:= _
" CommandExec dictionary 'default' form 'Command_Financial' command 'GL_Transaction_Entry'"
Selection.TypeParagraph
Selection.TypeText Text:= _
"NewActiveWin dictionary 'default' form 'GL_Transaction_Entry' window 'GL_Transaction_Entry'"
Selection.TypeParagraph
Selection.TypeText Text:= _
"WindowMove dictionary 'default' form 'GL_Transaction_Entry' window 'GL_Transaction_Entry' pointh 283 pointv -137"
Selection.TypeParagraph
Selection.TypeText Text:= _
"WindowSize dictionary 'default' form 'GL_Transaction_Entry' window 'GL_Transaction_Entry' pointh 562 pointv 979"
Selection.TypeParagraph
Selection.EndKey Unit:=wdStory
Selection.TypeText Text:= _
"ActivateWindow dictionary 'default' form sheLL window sheLL"
Selection.TypeParagraph
'
'Save the merged documant as a Plain Text file with a .mac extensionWord document
'
ChangeFileOpenDirectory "K:\Software\Dynamics\Automate JEs\"
ActiveDocument.SaveAs FileName:= _
"K:\Software\Dynamics\Automate JEs\ImportJE.mac", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF
ActiveDocument.Close
'
'Close Mail Merge document
Windows("JE Import Mail Merge Template - Batches.doc [Compatibility Mode]").Activate
ActiveDocument.Close
'
End Sub


The one thing I see that I think could be the problem is that when the mail merge template opens it says it is in Compatibility Mode. Is there a way to turn that off?
Reply With Quote
Reply

Tags
word macro from excel

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On