What is the exact wording of the error message when it fails? Does it help to
remove the "pause:=True" part?
--
Regards,
Jay Freedman
Microsoft Word MVP Word MVP FAQ site: http://www.mvps.org/word
"julián atienza" <julian...@hotmail.com> wrote in message
news:OHCdElkwBHA.2112@tkmsftngp02...
> I´m trying to create Word mailing labels with Mail Merge.
> I ´ve just copied the code generated by recording a Word macro; but when i
> execute the macro it produces an error at line
> "ActiveDocument.MailMerge.Execute pause:=True"
> I can´t understand why it fails here. Could anybody help me?
> thanks a lot.
Hi, Julián,
That error isn't one I'm familiar with (when I check it in Word VBA, it says
it's an "Application-defined or object-defined error"). But what I suspect is
that the merge fields in the main merge document don't match the field names in
Access. This may be because of a spelling error in the merge fields, or because
the merge document is not properly opened, or because there's something wrong
with the Access database.
--
Regards,
Jay Freedman
Microsoft Word MVP Word MVP FAQ site: http://www.mvps.org/word
"julián atienza" replied:
>The error is :
>-Error "4605" in executing time:
>this method or property is not available because The principal active
>document of combination of correspondence does not have combination
>fields- If i remove pause:=True the program fails with the same error;
>and if i remove all the sentence
>-ActiveDocument.MailMerge.Execute pause:=True -
>it creates a Word document with mailing labels fields empty-it doesn´t
>read any data from Access-.
"Jay Freedman" <jay.fr...@verizon.net> wrote in message
news:OJxuZWlwBHA.2020@tkmsftngp02...
Private Sub cmdWord_Click()
Dim w As New Word.Application
w.Documents.Add
w.ChangeFileOpenDirectory (App.Path)
w.ActiveDocument.SaveAs FileName:="VBASample_" & _
".doc", _
FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", _
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
w.ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels
w.ActiveDocument.MailMerge.OpenDataSource Name:= _
App.Path & "\julian.mdb", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="",
_
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False,
_
Format:=wdOpenFormatAuto, Connection:="TABLE julian", SQLStatement:=
_
"SELECT Nombre, Dni FROM [julian]", SQLStatement1:=""
w.Application.MailingLabel.DefaultPrintBarCode = False
'w.Application.MailingLabel.CreateNewDocument
w.Application.MailingLabel.CreateNewDocument Name:="2160 mini", Address:=
_
"Nombre: «Nombre»" & Chr(13) & "dni: «Dni»" & Chr(13), AutoText:="",
_
LaserTray:=wdPrinterManualFeed
If ActiveDocument.MailMerge.State = wdMainAndDataSource Then
With w.ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute pause:=True 'this method is not implemented in the active
document
End With
End If
w.ActiveDocument.SaveAs FileName:="etiquetas.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
'crea las etiquetas************************************************
'cierra el documento sin guardar los cambios
w.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'termina la aplicación Word
w.Application.Quit
Set w = Nothing
End Sub
"Jay Freedman" <jay.fr...@verizon.net> escribió en el mensaje
news:O7kRn5vwBHA.2520@tkmsftngp05...
I think your idea about a problem with the ActiveDocument is correct. I believe
that after the .CreateNewDocument statement, the ActiveDocument object refers to
the one that you have just created -- that is, the ActiveDocument object no
longer refers to the main merge document. That's why you're getting an error
message that says (in English translation) that the main merge document does not
contain merge fields.
I think you should try something like this:
Private Sub cmdWord_Click()
Dim w As New Word.Application
Dim oDoc as Word.Document
Set oDoc = w.Documents.Add
Then in the rest of your macro, replace w.ActiveDocument with oDoc. Then oDoc
will refer to the same document, the main merge document, throughout the macro,
even though some other document may become the ActiveDocument.
At the end of the macro, where you set w = Nothing, you should also set oDoc =
Nothing.
--
Regards,
Jay Freedman
Microsoft Word MVP Word MVP FAQ site: http://www.mvps.org/word
"julián atienza" <julian...@hotmail.com> wrote in message
news:O#BbEpxwBHA.2724@tkmsftngp03...