ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,731
- Office Version
- 2007
- Platform
- Windows
I am using the code below of which within there is a section to check if the file has allready been saved & stop the proces
I run the code & the msg to show Customers File Has Allready Been Saved is shown whether it has or hasnt.
I run the code & the msg to show Customers File Has Allready Been Saved is shown whether it has or hasnt.
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"
.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
If Dir(strFileName) = "" Then
.Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
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"
Unload PrinterForm
Dim strFolder As String
strFolder = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\"
ActiveWorkbook.FollowHyperlink Address:=strFolder, NewWindow:=True
End If
Exit Sub
With ActiveSheet
'ActiveWindow.SelectedSheets.PrintOut copies:=1
Unload PrinterForm
.Range("B3").Select
Application.ScreenUpdating = False
Dim C As Range
Dim ans As String
Dim Lastrow As Long
ans = ActiveCell.Value
Set wb = Application.Workbooks.Open("C:\Users\Ian\Desktop\REMOTES ETC\DR\DR.xlsm")
Lastrow = Sheets("POSTAGE").Cells(Rows.Count, "B").End(xlUp).Row
For Each C In Sheets("POSTAGE").Range("B1:B" & Lastrow)
If C.Value = ans Then
Application.Goto Reference:=wb.Sheets("POSTAGE").Range(C.Address)
ActiveWindow.ScrollColumn = 1
Exit For
End If
Next
End With
End With
Application.Run ("'" & wb.Name & "'!openForm")
Application.ScreenUpdating = True
End Sub