MS Office Forum / Word / Programming / October 2006
Macro won't print under XP...?
|
|
Thread rating:  |
Kenneth - 06 Oct 2006 18:55 GMT Howdy,
I had a macro (Word 2000 SP3) that worked properly under Win 2000 Pro.
Now, under Win XP, it behaves differently. Formerly, it did a merge, and printed the result. Now, instead, it does the merge, and opens the Print Dialog. There it stays until I click "OK" to print.
I had tried SendKeys "~" but with no luck.
Originally, I had created the macro by recording, and then tweaking.
With the help of a kind person on another group, I stripped out the extraneous stuff that the recorded generates to get the code just below.
It generates the Run Time Error 438 "Object doesn't support this property or method on the line I have marked.
Sub Macro8() ' ' NameTagsFirst Macro ' Macro created 5/30/2002 by Kenneth ' ' Documents.Add Template:="F:\Templates\Label 4x2.dot" ActivePrinter = "OKI" Selection.Font.Size = 36 Selection.Font.Bold = True With ActiveDocument.MailMerge .MainDocumentType = wdMailingLabels .OpenDataSource Name:="Z:\data\let.txt" .EditMainDocument .Fields.Add Range:=Selection.Range, Name:="First" >>>>> WordBasic.MailMergePropagateLabel <<<<<<< .Destination = wdSendToPrinter .SuppressBlankLines = True .Execute End With
ActivePrinter = "HP Color LaserJet 2500 PCL 6" ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges Application.ScreenUpdating = True Application.Quit
End Sub
Apparently, Word 2000 does not support WordBasic.MailMergePropagateLabel, but I don't know what to replace that with.
I will also add that in my original version, I did not record choosing "Mailing Labels." Instead, I chose "Formletters" though, in fact, I was printing those "letters" using a template that was 4"x2".
Thanks for any help on this,
 Signature Kenneth
If you email... Please remove the "SPAMLESS."
Doug Robbins - Word MVP - 08 Oct 2006 21:51 GMT See the article "How to do a mail merge to the printer using VBA, without displaying the Print dialog" at:
http://www.word.mvps.org/FAQs/MailMerge/MergeStraightToPrintrWVBA.htm
 Signature Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis.
Doug Robbins - Word MVP
> Howdy, > [quoted text clipped - 59 lines] > > Thanks for any help on this, Kenneth - 09 Oct 2006 22:17 GMT >See the article "How to do a mail merge to the printer using VBA, without >displaying the Print dialog" at: > >http://www.word.mvps.org/FAQs/MailMerge/MergeStraightToPrintrWVBA.htm Hi Doug,
I sincerely appreciate your help, but still can't seem to get this thing working.
Here is the code as I have it now:
Sub NameTagsFirst() ' ' NameTagsFirst Macro ' Macro created 5/30/2002 by Kenneth ' ' Documents.Add Template:= _ "F:\Templates\Label 4x2.dot" _ , NewTemplate:=False, DocumentType:=0 With ActiveDocument.PageSetup .TopMargin = InchesToPoints(0.7) End With Documents.Open FileName:="Z:\Data\let.txt", ConfirmConversions:=False, ReadOnly:= _ False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _ "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _ Format:=wdOpenFormatAuto Selection.TypeText Text:="First" & vbTab Selection.TypeParagraph ActiveDocument.Save ActiveWindow.Close Selection.Font.Size = 36 Selection.Font.Bold = wdToggle ActiveDocument.MailMerge.MainDocumentType = wdFormLetters ActiveDocument.MailMerge.OpenDataSource Name:="Z:\data\let.txt", _ ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _ AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _ WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _ Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1 _ :="" ActiveDocument.MailMerge.EditMainDocument ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:="First" ActivePrinter = "OKI" With ActiveDocument.MailMerge .ActiveDocument.MailMerge.Destination = ^^^^^^^^^^^^^^^wdSendToNewDocument .ActiveDocument.PrintOut Background:=False .MailAsAttachment = False .MailAddressFieldName = "" .MailSubject = "" .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=True End With
ActivePrinter = "HP Color LaserJet 2500 PCL 6"
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges Application.ScreenUpdating = True Application.Quit
End Sub
The problem is that I get a compile error on the line:
.ActiveDocument.MailMerge.Destination = wdSendToNewDocument
The error is "Method or data member not found" and the blue "cursor" appears on ".AcctiveDocument" as I have marked with "^^^^^" above.
By the way, (as is probably obvious) I know next to nothing about using VBA. I have created the code above by using the recorder, and then tweaking manually. As a result, there is quite a bit of junk that is of no value.
I had this macro (and several others that are similar) working just fine. I had thought that the problem started when I moved to a new system that ran XP, but now, based on the link you provided, I suspect that the problem was that I may have been using the macros with a later version of Word than the Word 2000 I am now using.
In any case, I would certainly welcome any further help you might provide.
Thanks again,
 Signature Kenneth
If you email... Please remove the "SPAMLESS."
Doug Robbins - Word MVP - 10 Oct 2006 18:50 GMT It should be:
With ActiveDocument.MailMerge .Destination = wdSendToNewDocument
Also, the
ActiveDocument.PrintOut
should be after the
.Execute Pause:=True End With
 Signature Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis.
Doug Robbins - Word MVP
>>See the article "How to do a mail merge to the printer using VBA, without >>displaying the Print dialog" at: [quoted text clipped - 106 lines] > > Thanks again, Kenneth - 10 Oct 2006 20:09 GMT >It should be: > [quoted text clipped - 9 lines] > .Execute Pause:=True >End With Hi Doug,
Well, I am making progress in the sense that I am getting different errors now...
Here is the current code, with the modifications you suggest:
Sub NameTagsFirst() ' ' NameTagsFirst Macro ' Macro created 5/30/2002 by Kenneth ' ' Documents.Add Template:= _ "F:\Templates\Label 4x2.dot" _ , NewTemplate:=False, DocumentType:=0 With ActiveDocument.PageSetup .TopMargin = InchesToPoints(0.7) End With Documents.Open FileName:="Z:\Data\let.txt", ConfirmConversions:=False, ReadOnly:= _ False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _ "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _ Format:=wdOpenFormatAuto Selection.TypeText Text:="First" & vbTab Selection.TypeParagraph ActiveDocument.Save ActiveWindow.Close Selection.Font.Size = 36 Selection.Font.Bold = wdToggle ActiveDocument.MailMerge.MainDocumentType = wdFormLetters ActiveDocument.MailMerge.OpenDataSource Name:="Z:\data\let.txt", _ ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _ AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _ WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _ Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1 _ :="" ActiveDocument.MailMerge.EditMainDocument ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:="First" ActivePrinter = "OKI" With ActiveDocument.MailMerge.Destination = ^^^^ wdSendToNewDocument .MailAsAttachment = False .MailAddressFieldName = "" .MailSubject = "" .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=True End With .ActiveDocument.PrintOut Background:=False
ActivePrinter = "HP Color LaserJet 2500 PCL 6"
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges Application.ScreenUpdating = True Application.Quit
End Sub
When I run it, I get the error:
"With object must be user-defined type, object, or varient." The blue error cursor is on the "With" of the line I have marked above with "^^^^^^".
Thanks for any further help,
 Signature Kenneth
If you email... Please remove the "SPAMLESS."
Kenneth - 11 Oct 2006 16:52 GMT >It should be: > [quoted text clipped - 9 lines] > .Execute Pause:=True >End With Hi Doug,
I believe that I have all this working now, and offer you my sincere thanks,
 Signature Kenneth
If you email... Please remove the "SPAMLESS."
|
|
|