ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,738
- Office Version
- 2007
- Platform
- Windows
Evening,
I am using the code supplied below.
I press the command button & the pdf is saved then the cells cleared so far all ok.
If i press the command button again im expecting the message box to be shown to advise me that the already exists.
This doesnt happen & the save continues once again.
I am using the code supplied below.
I press the command button & the pdf is saved then the cells cleared so far all ok.
If i press the command button again im expecting the message box to be shown to advise me that the already exists.
This doesnt happen & the save continues once again.
Code:
Private Sub GrassSummaryIncomeSheet_Click() Dim strFileName As String
strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\INCOME 2019-2020\" & _
Range("J3") & "_" & Format(Month(DateValue(Range("G3") & " 1, " & "2019")), "00") & " " & Range("G3")
If Dir(strFileName) <> vbNullString Then
MsgBox "INCOME GRASS SHEET " & Range("G3") & " " & Range("J3") & " WAS NOT SAVED AS IT ALREADY EXISTS", vbCritical + vbOKOnly, "INCOME SUMMARY GRASS SHEET MESSAGE"
Exit Sub
End If
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True
MsgBox "GRASS SHEET " & Range("G3") & " " & Range("J3") & " WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly, "INCOME SUMMARY GRASS SHEET MESSAGE"
Range("G5:H30").ClearContents
Range("G5").Select
ActiveWorkbook.Save
End With
End Sub