Skip to content

Instantly share code, notes, and snippets.

@Mahno74
Last active September 11, 2024 08:49
Show Gist options
  • Save Mahno74/265a423bcbefc46cb6b8bb49261f8d4c to your computer and use it in GitHub Desktop.
Save Mahno74/265a423bcbefc46cb6b8bb49261f8d4c to your computer and use it in GitHub Desktop.
WORD Макросы для сохранения слияния и рассылки в отдельные файлы формата DOC или PDF
Sub ToTranslitDoc()
Dim i As Long
Dim oMerge As MailMerge
Dim oData As MailMergeDataSource
Set oMerge = ActiveDocument.MailMerge
Set oData = oMerge.DataSource
Application.ScreenUpdating = False
For i = 1 To oData.RecordCount
With oData
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
End With
With oMerge
.Destination = wdSendToNewDocument
.Execute Pause:=False
End With
With ActiveDocument
.SaveAs ("d:\TMP\" & oData.DataFields("Translit").Value & ".doc")
.Close
End With
Next i
Set oData = Nothing
Set oMerge = Nothing
Application.ScreenUpdating = True
End Sub
Sub ToTranslitPdf()
Dim i As Long
Dim oMerge As MailMerge
Dim oData As MailMergeDataSource
Set oMerge = ActiveDocument.MailMerge
Set oData = oMerge.DataSource
Application.ScreenUpdating = False
For i = 1 To oData.RecordCount
With oData
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
End With
With oMerge
.Destination = wdSendToNewDocument
.Execute Pause:=False
End With
With ActiveDocument
.SaveAs FileName:="d:\TMP\" & oData.DataFields("Translit").Value & ".pdf", FileFormat:=wdFormatPDF
.Close (False)
End With
Next i
Set oData = Nothing
Set oMerge = Nothing
Application.ScreenUpdating = True
End Sub
@AlexanderTats
Copy link

Подскажите, пожалуйста, как можно воспользоваться данным макросом, как его правильно настроить и применять? Извините, первый раз сталкиваюсь с макросами, нужен ликбез.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment