Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-17-2016, 10:24 AM
moneal62 moneal62 is offline 5941 error message in macro used in merge Windows 7 64bit 5941 error message in macro used in merge Office 2010 64bit
Novice
5941 error message in macro used in merge
 
Join Date: Jan 2016
Posts: 4
moneal62 is on a distinguished road
Default 5941 error message in macro used in merge

All, I have a mail merge and macro that has been running since 2003 that has all of a sudden stopped working with a 5941 error message. Word 2010. It debugs on the last line:





Windows("M_HERBARIUM_LABEL.DOTX").Activate



Here is the whole code, any help greatly appreciated, thank you.

Mike O.



***

Sub MERGE_DEFAULT()
'
' MERGE_DEFAULT Macro
' Macro recorded 9/25/2003 by Greg Harmison
'

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = True
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
Application.Templates.LoadBuildingBlocks
Windows("M_HERBARIUM_LABEL.DOTX").Activate
End Sub
Reply With Quote
  #2  
Old 01-17-2016, 01:53 PM
macropod's Avatar
macropod macropod is online now 5941 error message in macro used in merge Windows 7 64bit 5941 error message in macro used in merge Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The error message is telling you that the file "M_HERBARIUM_LABEL.DOTX" isn't open.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-17-2016, 02:36 PM
moneal62 moneal62 is offline 5941 error message in macro used in merge Windows 7 64bit 5941 error message in macro used in merge Office 2010 64bit
Novice
5941 error message in macro used in merge
 
Join Date: Jan 2016
Posts: 4
moneal62 is on a distinguished road
Default

Thanks Paul, but I am running that macro from within the document itself, which is already open.
Reply With Quote
  #4  
Old 01-17-2016, 04:06 PM
macropod's Avatar
macropod macropod is online now 5941 error message in macro used in merge Windows 7 64bit 5941 error message in macro used in merge Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The line:
Windows("M_HERBARIUM_LABEL.DOTX").Activate
is trying to activate a the file named "M_HERBARIUM_LABEL.DOTX". By definition, any .DOTX file is a template, not a document. When you double-click on a template, Word creates a new document (typically named Document1 or something such).

Furthermore, if the macro is in a template, that template cannot have a .DOTX extension, as the DOTX format does not support macros; a .DOT or .DOTM extension would be required.

You say you've been using this macro since 2003, but the DOTX format did not exist back then - it was introduced with Word 2007.

As for the code itself, it contains redundant lines that are only relevant for email merges and, do you realise the only (practical?) thing it does is to eliminate a few mouse clicks and switch back to the mailmerge main document after merging (so you then have to switch back to the output document before you can use it)?

Finally, for the purposes of a mailmerge, you should be using a mailmerge main document, not a template. Since you're using macros, that document would have to be saved in the DOC or DOCM format. So as to not get tangled up with possible name changes to the mailmerge main document, you might change the code to:
Code:
Sub MERGE_DEFAULT()
Dim Doc As Document
Set Doc = ActiveDocument
With Doc.MailMerge
  .Destination = wdSendToNewDocument
  .SuppressBlankLines = True
  With .DataSource
    .FirstRecord = wdDefaultFirstRecord
    .LastRecord = wdDefaultLastRecord
  End With
  .Execute Pause:=False
  .Activate
End With
End Sub
PS: When posting code, please use the code tags, indicated by the # button on the posting menu.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 01-18-2016, 09:23 AM
moneal62 moneal62 is offline 5941 error message in macro used in merge Windows 7 64bit 5941 error message in macro used in merge Office 2010 64bit
Novice
5941 error message in macro used in merge
 
Join Date: Jan 2016
Posts: 4
moneal62 is on a distinguished road
Default

Hello Paul - Greatly appreciate the response and on how to post code. More background on this - from our database application we are building a command line string that opens Word, opens a merge document and passes in a text file, runs the macros, and completes the merge. It really *has* worked since 2003, the code I posted contained my (bungled) attempts at fixing it recently.

In our string I have now changed it to a .DOTM file and made progress - I still receive the error message but the file *does* merge. But, each merged record is on it's own page, whereas previously we had six labels per page. (these are scientific labels for labeling botanical specimens, not mailing labels). When I tried the code you posted, with just .ACTIVATE, I get "Invalid or Unqualified Reference". Sounds like I need something in from of .ACTIVATE?

Thank you again, very much.

Mike O.
Reply With Quote
  #6  
Old 01-18-2016, 02:06 PM
moneal62 moneal62 is offline 5941 error message in macro used in merge Windows 7 64bit 5941 error message in macro used in merge Office 2010 64bit
Novice
5941 error message in macro used in merge
 
Join Date: Jan 2016
Posts: 4
moneal62 is on a distinguished road
Default

Also discovered if I remove .ACTIVATE from the last line the merge completes without an error message, but every record is still on a single page - looking to get back the functionality of multiple labels on a single page (see attached). Thank you for any continued help.

Mike O.
Attached Images
File Type: jpg labels_6.jpg (142.9 KB, 15 views)
Reply With Quote
  #7  
Old 01-18-2016, 07:54 PM
macropod's Avatar
macropod macropod is online now 5941 error message in macro used in merge Windows 7 64bit 5941 error message in macro used in merge Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Actually, the code I posted should have been:
Code:
Sub MERGE_DEFAULT()
Dim Doc As Document
Set Doc = ActiveDocument
With Doc
  With .MailMerge
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True
    With .DataSource
      .FirstRecord = wdDefaultFirstRecord
      .LastRecord = wdDefaultLastRecord
    End With
    .Execute Pause:=False
  End With
  .Activate
End With
End Sub
As for getting one label per page, that's because someone has changed the merge type from label to letter. That can be fixed via the GUI or with:
Code:
Sub MERGE_DEFAULT()
Dim Doc As Document
Set Doc = ActiveDocument
With Doc
  With .MailMerge
    .MainDocumentType = wdMailingLabels
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True
    With .DataSource
      .FirstRecord = wdDefaultFirstRecord
      .LastRecord = wdDefaultLastRecord
    End With
    .Execute Pause:=False
  End With
  .Activate
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error 5941 when running my macro to auto populate fields throughout the word doc VBAnovice1 Word VBA 2 05-26-2015 01:35 AM
Help Please: New VBA user trying to use a macro to split Mail Merge documents. Two Run-Time Error zipit189 Word VBA 7 03-18-2015 01:13 PM
Run-time error 5941 when deleting a row from a table jpb103 Word VBA 1 05-26-2014 07:08 AM
5941 error message in macro used in merge Mail Merge error message rec Mail Merge 1 04-29-2011 10:30 PM
Error Message in Mail Merge A Bhavani Mail Merge 0 11-26-2008 12:08 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:24 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft