Try this, it should fit your need.
However, there have some different.
1. final message box will have some different.
2. another message box will incur if cancel overwrite. to ask you whether to continue to next tab.
please let me know if you need further amendment.
Option Explicit
Sub Apdf()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
Dim lOver As Long
Dim Counter, TotalSht As Integer
Dim answer As String
Counter = 0
On Error Resume Next
Set wbA = ActiveWorkbook
TotalSht = wbA.Worksheets.Count
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
For Each wsA In wbA.Worksheets
strName = wsA.Range("A1").Value _
& " - " & wsA.Range("A2").Value _
& " - " & wsA.Range("A3").Value
'create default name for savng file
strFile = strName & ".pdf"
strPathFile = strPath & strFile
If bFileExists(strPathFile) Then
lOver = MsgBox("Overwrite existing file?", _
vbQuestion + vbYesNo, "File Exists")
If lOver <> vbYes Then
'user can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
title:="Select Folder and FileName to save")
If myFile <> "False" Then
strPathFile = myFile
Else
answer = MsgBox("This save has canceled." & vbNewLine _
& "Continue to next tab?", vbOKCancel, "File to Save")
If answer = vbCancel Then
GoTo Summary
Else
GoTo Bottom
End If
End If
End If
End If
'export to PDF in current folder
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPathFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Counter = Counter + 1
Bottom:
Next
'confirmation message with file info
Summary:
MsgBox Counter & "/" & TotalSht & " PDF file(s) has been created at: " _
& vbCrLf & strPath
End Sub
'=============================
Function bFileExists(rsFullPath As String) As Boolean
bFileExists = CBool(Len(Dir$(rsFullPath)) > 0)
End Function
'=============================
Bookmarks