Sub Word_ExportPDF()
Dim CurrentFolder As String
Dim FileName As String
Dim myPath As String
Dim UniqueName As Boolean
UniqueName = False
myPath = ActiveDocument.FullName
CurrentFolder = ActiveDocument.Path & "\"
FileName = Mid(myPath, InStrRev(myPath, "\") + 1, _
InStrRev(myPath, ".") - InStrRev(myPath, "\") - 1)
Do While UniqueName = False
DirFile = CurrentFolder & FileName & ".pdf"
If Len(Dir(DirFile)) <> 0 Then
UserAnswer = MsgBox("File Already Exists! Click " & _
"[Yes] to override. Click [No] to Rename.", vbYesNoCancel)
If UserAnswer = vbYes Then
UniqueName = True
ElseIf UserAnswer = vbNo Then
Do
FileName = InputBox("Provide New File Name " & _
"(will ask again if you provide an invalid file name)", _
"Enter File Name", FileName)
If FileName = "False" Or FileName = "" Then Exit Sub
Loop While ValidFileName(FileName) = False
Else
Exit Sub
End If
Else
UniqueName = True
End If
Loop
On Error GoTo ProblemSaving
ActiveDocument.ExportAsFixedFormat _
OutputFileName:=CurrentFolder & FileName & ".pdf", _
ExportFormat:=wdExportFormatPDF
On Error GoTo 0
With ActiveDocument
FolderName = Mid(.Path, InStrRev(.Path, "\") + 1, Len(.Path) - InStrRev(.Path, "\"))
End With
MsgBox "PDF Saved in the Folder: " & FolderName
Exit Sub
ProblemSaving:
MsgBox "There was a problem saving your PDF. This is most commonly caused" & _
" by the original PDF file already being open."
Exit Sub
End Sub