Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Barbara,
Per le mie prove ho
creato un file Excel con una tabella Excel di nomi e ho utillizato Nome e Cognome come le intestazione della tabella
In un file Word ho creato, a mano, un documento MailMerge, legando il documento alla tabelle Excel.
In un modulo standard del file Word, ho incollato il seguente codice:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim MyDoc As Document
Dim sStr As String, sFolder As String, sName As String, sPath As String
Dim i As Long, j As Long
On Error GoTo ErrHandler
With Application
sStr = .PathSeparator
.ScreenUpdating = False
End With
Set MyDoc = ThisDocument
With MyDoc
sFolder = .Path & sStr
For i = 1 To .MailMerge.DataSource.RecordCount
With .MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
If Trim(.DataFields("Nome")) = "" Then
Exit For
End If
sName = .DataFields("Cognome") _
& "_" _
& .DataFields("Nome")
End With
.Execute Pause:=False
End With
For j = 1 To 255
Select Case j
Case 1 To 31, 33, 34, 37, 42, 44, 46, 47, _
58 - 63, 91 - 93, 96, 124, 147, 148
sName = Replace(sName, Chr(j), "")
End Select
Next
sName = Trim(sName)
With ActiveDocument
.SaveAs FileName:=sPath & sName & ".pdf", _
FileFormat:=wdFormatPDF, _
AddToRecentFiles:=False
.Close SaveChanges:=False
End With
Next i
End With
XIT:
On Error GoTo 0
Application.ScreenUpdating = True
Exit Sub
ErrHandler:
Call MsgBox(Prompt:=Err.Description & " " & Err.Number, _
Buttons:=vbCritical, _
Title:="Errore")
Resume XIT
End Sub
'<<=========
Legando il documento MailMerge al mio file Excel precedente (Barbara20150831.xlsm ), ci sono stati salvati 26 file pdf. uno per ciascun nome della tabella.
===
Regards,
Norman