ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,596
- Office Version
- 2007
- Platform
- Windows
Hi,
I am using the code below to see if file is in folder before saving.
If Yes show msgbox to advise user.
If No then continue with the save.
My problem is that i see the Msgbox PDF ALLREADY GENERATED WHETHER IT IT OR IT ISNT.
Do you see why Thanks.
I am using the code below to see if file is in folder before saving.
If Yes show msgbox to advise user.
If No then continue with the save.
My problem is that i see the Msgbox PDF ALLREADY GENERATED WHETHER IT IT OR IT ISNT.
Do you see why Thanks.
VBA Code:
Private Sub PurchasedCode_Click()
Dim sPath As String
Dim strFileName As String
Dim sh As Worksheet
With ActiveSheet
If .Range("Q1") = "" Then
MsgBox "NO CODE SHOWN TO GENERATE PDF", vbCritical, "NO CODE ON SHEET TO CREATE PDF"
Exit Sub
End If
If .Range("N1") = "M" Then
Dim File As String
File = PurchasedCode.Value ' CUSTOMERS NAME IN USERFORM TEXTBOX
Dim DirFile As String
DirFile = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF" & File ' PATH TO WHERE PDF FILES ARE SAVED
If Dir(DirFile) = "" Then ' IF FILE DOES NOT EXISTS THEN CONTINUE TO SAVE FILE
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " (SLS).pdf"
.Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
Else
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & ".pdf"
.Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
End If
Else ' IF FILE IS PRESENT DO NOT ALLOW FILE TO BE OVERWRITTEN & TO SHOW MSGBOX
MsgBox "PDF ALLREADY GENERATED", vbCritical + vbOKOnly, "PDF ALLREADY GENERATED MESSAGE"
End If
Exit Sub
.Range("B3").Select
Unload PrinterForm
MsgBox "PDF FILE HAS NOW BEEN GENERATED", vbInformation + vbOKOnly, "GENERATE PDF FILE MESSAGE"
End With
End Sub