Buongiorno Maurizio, ho letto tutto l'argomento perché ho la stessa problematica da risolvere, nel momento in cui lancio la macro test2 Word (2013) mi dice che "il membro richiesto della raccolta non esiste". Da cosa potrebbe dipendere?
il documento è di formato Doc di word con attivazione Macro
questo è il codice inserito nel file, nel mio file Excel origine dati il campo di interesse si chiama Nome
Public Sub Test2()
On Error GoTo ErrH
' --- PERSONALIZZARE ---------- >
' Percorso di salvataggio dei file PDF:
Const cstrPath As String = "O:\Circolari Sito"
' Nome del Campo di stampa unione che dà il nome
' ai file pdf:
Const cstrField As String = "Nome"
' ----------------------------- <
Dim objWdMailMerge As Word.MailMerge
Dim lngRecNum As Long
Dim strPath As String
Dim strFilename As String
Application.ScreenUpdating = False
Set objWdMailMerge = ThisDocument.MailMerge
With objWdMailMerge
.Destination = wdSendToNewDocument
With .DataSource
.ActiveRecord = wdLastRecord
lngRecNum = .ActiveRecord
.ActiveRecord = wdFirstRecord
Do
.FirstRecord = .ActiveRecord
.LastRecord = .ActiveRecord
strFilename = .DataFields(cstrField).Value
If Len(strFilename) Then
strFilename = cstrPath & strFilename
objWdMailMerge.Execute
With ActiveDocument
.SaveAs strFilename, wdFormatPDF, AddToRecentFiles:=False
.Saved = True
.Close
End With
End If
If .ActiveRecord = lngRecNum Then Exit Do
.ActiveRecord = wdNextRecord
Loop
End With
End With
ExitProc:
Application.ScreenUpdating = True
Set objWdMailMerge = Nothing
Exit Sub
ErrH:
MsgBox Err.Description
Resume ExitProc
End Sub
grazie mille, Andrea