Hi macropod,
thank you for assisting me
I had already read that kb, but it should not apply to my case, because the excel table (the oDataDoc in the MS example) is closed.
The
Have time to take a look at my code? (the point rows are code of no importance)
Code:
Private Sub cmdRegistraVerbale_Click()
......................................
Workbooks.Open Filename:=archivio
......................................
numero = ActiveCell.Value
......................................
Workbooks(archivio).Save ' i know it's useless (could use 'true' in next)
Workbooks(archivio).Close (False) ' but who knows...
......................................
On Error Resume Next
Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdocSource = wd.Documents.Open(modverbale)
wdocSource.MailMerge.MainDocumentType = wdFormLetters
With wdocSource.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = numero
.LastRecord = numero
End With
.Execute Pause:=False ' error 5631 here
End With
wdocSource.MailMerge.DataSource.Close
wd.Visible = True
With wd.Documents(wd.ActiveDocument.FullName)
.SaveAs ("newfile.doc")
.PrintOut
.Close
End With
wdocSource.Close SaveChanges:=False
wd.NormalTemplate.Saved = True
'archivio' is an .xls file (1 sheet)
'modverbale' the .doc file in which the links to the table are embedded
'numero' the record number (the last one) to be merged.
the 'archivio' seems to be saved correctly, the last record is there.
I tried to change the name to both files, creating from scratch the new .doc and thus rebuilding the SQL link: at first, it seems to work (the MailMerge wizard sees all the records), but the sub stops at the very same place