0
I used this code to generate a direct mail and separate the files.
But the following mistake is being made:
Runtime error "5852" The requested object is not available.
Use of office 365
Sub SalvarComoDOCIndividual()
Dim a As Integer
Dim registro As Integer
Dim nomeArquivo As String
'Define o primeiro registro da mala direta
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
'Contador de registros
a = ActiveDocument.MailMerge.DataSource.RecordCount
'Salva todos os registros
For registro = 1 To a
'Atribui o valor de cada registro da coluna nome para a variável nomeArquivo que dará nome ao novo arquivo. Caso queira outro nome, basta colocar o nome da coluna desejada
nomeArquivo = ActiveDocument.MailMerge.DataSource.DataFields("ALUNO").Value
ActiveDocument.SaveAs2 FileName:= _
"C:\Users\usuario\arquivos\" & nomeArquivo & ".docx", FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=15
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Next registro
End
End Sub
Failed to explain in which line the error occurs.
– César Rodriguez