Hi Folks,
I got the below code from another forum which creates a folder and saves the file as a pdf in it. What I would like now is that if the folder already exists to save the file with number suffix at the end e.g. test1.pdf or test(1).pdf
Thanks,
Fra
Sub newFolder()
Dim strNewFolderName As String
strNewFolderName = "Attendance Register " & ActiveDocument.MailMerge.DataSource.DataFields("Text_Display").Value 'Needs to be text value
If Len(Dir("I:\Computer Programming\Languages\VBA\Mail Merge\Attendance Registers" & strNewFolderName, vbDirectory)) = 0 Then
MkDir ("I:\Computer Programming\Languages\VBA\Mail Merge\Attendance Registers\" & strNewFolderName)
End If
Dim PathName As String
PathName = ("Attendance Register " & (ActiveDocument.MailMerge.DataSource.DataFields("Text_Display").Value))
ActiveDocument.SaveAs FileName:="I:\Computer Programming\Languages\VBA\Mail Merge\Attendance Registers\" & strNewFolderName & "\" & Split(ActiveDocument.Name, ".")(0) & " " & ActiveDocument.MailMerge.DataSource.DataFields("Text_Display").Value & ".pdf", _
FileFormat:=wdFormatPDF
End Sub