ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,731
- Office Version
- 2007
- Platform
- Windows
Morning.
My code is shown below.
A folder on my pc has saved pdf documents & more are added each day.
I am trying to stop duplicates being saved so my code below should be doing that but doesnt.
From my userform i generate the pdf & save it to the folder in question.
The code checks this folder & if it the file is present i see the Msgbox CUSTOMERS FILE HAS ALLREADY BEEN SAVED & then the exit sub kicks in & i am taken to the pdf folder to take a look.
What i have noticed is that even though i am told the file exists its still being saved so example, I now have two files called TOM JONES 001 & should only have the 1.
Do you see my mistake & advise me please.
My code is shown below.
A folder on my pc has saved pdf documents & more are added each day.
I am trying to stop duplicates being saved so my code below should be doing that but doesnt.
From my userform i generate the pdf & save it to the folder in question.
The code checks this folder & if it the file is present i see the Msgbox CUSTOMERS FILE HAS ALLREADY BEEN SAVED & then the exit sub kicks in & i am taken to the pdf folder to take a look.
What i have noticed is that even though i am told the file exists its still being saved so example, I now have two files called TOM JONES 001 & should only have the 1.
Do you see my mistake & advise me please.
VBA Code:
Private Sub PurchasedKey_Click()
Dim sPath As String
Dim strFileName As String
Dim sh As Worksheet
Dim wb As Workbook
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
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " (SLS).pdf"
Else
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & ".pdf"
End If
If Dir(strFileName) = "" Then
.Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
MsgBox "PDF FILE HAS NOW BEEN SAVED", vbInformation + vbOKOnly, "SAVED PDF FILE MESSAGE"
With ActiveSheet
'ActiveWindow.SelectedSheets.PrintOut copies:=1
Unload PrinterForm
Set wb = Application.Workbooks.Open("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
Worksheets("POSTAGE").Activate
Application.Goto Sheets("POSTAGE").Range("A" & Rows.Count).End(xlUp), True
ActiveWindow.SmallScroll UP:=14
End With
Else
'IF FILE IS PRESENT DO NOT ALLOW FILE TO BE OVERWRITTEN & TO SHOW MSGBOX
MsgBox "CUSTOMERS FILE HAS ALLREADY BEEN SAVED", vbCritical + vbOKOnly, "FILE ALLREADY SAVED MESSAGE"
Dim strFolder As String
strFolder = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\"
ActiveWorkbook.FollowHyperlink Address:=strFolder, NewWindow:=True
Unload PrinterForm
Exit Sub
End If
End With
Call DISCOHYPERLINK
End Sub