Mail Merge VBA - Runtime Error 4605

SimonGeoghegan

Board Regular
Joined
Nov 5, 2013
Messages
68
Hi All,

I have some VBA code within Microsoft Word that loops through and creates a number of mail merged documents.

When running, I receive a "Run-time error 4605: This command is not available" error message. When I debug the code, is it stopping on the "ActiveDocument.Range.Paste" line below. Once at the debug screen, if I then continue the code (F5) straight away, it works as expected, until the loop comes around to this same section.

VBA Code:
    Set Doc = ActiveDocument
        Doc.Range.Copy
        Documents.Add
        ActiveDocument.Range.Paste
        ActiveDocument.SaveAs (strPath & "\" & ReportingMonth & "\" & "Clinical Governance Report - " & ReportingMonth & " - " & Hospital & ".doc")
        ActiveDocument.Close False

I can execute all of my code if I sit and debug & F5 each time it breaks - but I'd prefer not to :)

Does anyone have any idea as to why the above section of code might be failing initially?

Thanks in advance!
Simon
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Speaking from Access vba experience, and to a lesser extent, Excel vba, if you Set Doc to be the ActiveDocument you want to do everything thereafter to it using Doc, not ActiveDocument.
If an active object loses the focus then trying to do anything to it by relying on the active object reference (in this case, ActiveDocument), you never know what effect it will have. Not sure if that will fix your problem, but that's where I'd start.
 
Upvote 0
Without access to more of your code, it's impossible to understand why you're doing what you're doing the way you're doing it. For code to run a mailmerge and produce individual output documents, see:
Send Mailmerge Output to Individual Files; and
Run a Mailmerge from Excel, Sending the Output to Individual Files,
in the Mailmerge Tips and Tricks page at:
Mailmerge Tips & Tricks
The code in the second link is easily adapted for running from Access, if needed.
 
Upvote 0

Forum statistics

Threads
1,224,853
Messages
6,181,412
Members
453,038
Latest member
muhsen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top