Brevflet avanceret
HejFor at gøre lang historie kort, så kigger jeg pt. på alternative løsninger i form af at gemme dokumenter i eget system for derefter at kunne blive sendt ud. Jeg fandt en gammel kode i trådende, hvorved brevflet var en løsning. Super fedt! Nu støder jeg så ind i et enkelt problem. Det skal meget gerne gemmes som PDF og ikke Word. Har i evt. et forslag til hvorved dette kan ændres i koden?
Sub MailMerge_OneDocPerLetter()
'First perform mail merge to new document, then run this macro
'to save each letter as a separate file
Dim strDocName As String
Dim oDoc As Document
Dim oDocNew As Document
Dim strFileName As String
Dim strFilePath As String
Dim nSections As Long
Dim nCount As Long
Set oDoc = ActiveDocument
nSections = oDoc.Sections.Count
'Replace path with the folder path to use
strFilePath = "C:\Brev\"
nCount = 4 - 1
Application.ScreenUpdating = False
While nCount < nSections
'Change the code line below if the name is found elsewhere
strDocName = oDoc.Paragraphs(4).Range.Text
'exclude parapraph mark
strDocName = Left(strDocName, Len(strDocName) - 1)
'append til path - replace ".doc" with ".docx" if file format must be 2007 or 2010
strDocName = strFilePath & strDocName & ".doc"
'cut section 1 and insert in new document
oDoc.Sections.First.Range.Cut
Set oDocNew = Documents.Add
With oDocNew
'make sure document is empty
.Range.Text = ""
'insert cut text
Selection.Paste
'save document with correct name
.SaveAs FileName:=strDocName, FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", _
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
.Close
End With
nCount = nCount - 1
Wend
'close the now empty oDoc without saving
oDoc.Close savechanges:=wdDoNotSaveChanges
'clean up
Set oDoc = Nothing
Set oDocNew = Nothing
Application.ScreenUpdating = True
MsgBox "Finished. Documents saved in folder:" & vbCr & _
strFilePath
End Sub