VBA warning message when saving PDF over existing file

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
370
Hi, would it be possible to have a warning box pop up to prevent saving the PDF over an existing file? Also, can we have the box show the existing filename and be able to change the name and then save it? Thanks

Code:
Sub DETAIL_PDF()
    Dim response As String
    Dim PrintAreaString As String
    response = InputBox("Enter column letter for 2nd part of range", "Enter Data")
    If response = Cancel Then
    Exit Sub
    End If
      Application.ScreenUpdating = False
      With ActiveSheet
        PrintAreaString = "A3:$" & Trim(UCase(response)) & "$" & .Range("B1").Value
        If response <> "" Then
            .PageSetup.PrintArea = PrintAreaString
            .PageSetup.Orientation = xlLandscape
            .PageSetup.Zoom = False
            .PageSetup.FitToPagesWide = 1
            .PageSetup.FitToPagesTall = False
            .PageSetup.LeftMargin = 36
            .PageSetup.TopMargin = 72
            .PageSetup.RightMargin = 36
            .PageSetup.BottomMargin = 36
    End If
    End With
    fileSaveName = ActiveWorkbook.Path & "\" & "FRIEDLAND QUOTE " & [B6] & " " & "JOB " & [B7] & " " & [A15] & " " & [AB15] & " " & [AD15] & [B9] & " PCS" & " " & Format(Date, "mmddyy")
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        fileSaveName _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=True '(change this to "False" to prevent the file from opening after saving)
    Application.ScreenUpdating = True
End Sub
 
I thought you wanted to show the message box only if the file already exists. Is it not working that way?
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top