ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,699
- Office Version
- 2007
- Platform
- Windows
Hi,
Code in use is shown below & works well.
Currenly the code in Red deletes an unwanted pdf & works well.
I now need to have another but i get an error message advising me the event is allready present.
Is there a way to have two or something the same.
Sometimes i generate a copy of the current invoice so say in this example Tom Jones 123.pdf
Its path is C:\Users\Ian\Desktop\REMOTES ETC\DR\DR SCREEN SHOT PDF
The saved file is named using the details in cell G13
Like i say SOMETIMES so my goal is to run this code supplied then if the copy file is present just delete it.
If there is no fil;e present then obviously ignore as nothing to delete.
The code would need to be towards the top of this code as opposed to the bottom.
Thanks
Code in use is shown below & works well.
Currenly the code in Red deletes an unwanted pdf & works well.
I now need to have another but i get an error message advising me the event is allready present.
Is there a way to have two or something the same.
Sometimes i generate a copy of the current invoice so say in this example Tom Jones 123.pdf
Its path is C:\Users\Ian\Desktop\REMOTES ETC\DR\DR SCREEN SHOT PDF
The saved file is named using the details in cell G13
Like i say SOMETIMES so my goal is to run this code supplied then if the copy file is present just delete it.
If there is no fil;e present then obviously ignore as nothing to delete.
The code would need to be towards the top of this code as opposed to the bottom.
Thanks
Rich (BB code):
Sub HYPERLINKP5()
Dim answer As Integer
Dim srcWS As Worksheet, destWS As Worksheet
Set srcWS = ActiveWorkbook.Worksheets("INV")
Set destWS = ActiveWorkbook.Worksheets("DATABASE")
If Trim(destWS.Range("P5").Value) <> "" Then
MsgBox ("CELL P5 HAS A INVOICE NUMBER IN IT ALREADY"), vbCritical, "CELL P5 ISNT EMPTY MESSAGE"
With Sheets("INV")
Worksheets("DATABASE").Activate
Worksheets("DATABASE").Range("P5").Select
End With
Exit Sub
Else
srcWS.Range("L4").Copy destWS.Range("P5")
With destWS
.Range("P5").Font.Size = 14
.Activate
.Range("P5").Select
Const FILE_PATH As String = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\"
If ActiveCell.Column = Columns("P").Column Then
If Dir(FILE_PATH & ActiveCell.Value & ".pdf") <> "" Then
ActiveCell.Hyperlinks.Add Anchor:=ActiveCell, Address:=FILE_PATH & ActiveCell.Value & ".pdf"
Else
ActiveCell.Hyperlinks.Delete
MsgBox (FILE_PATH & ActiveCell.Value & ".pdf" & vbNewLine & vbNewLine & "FILE IS NOT IN FOLDER SPECIFIED, PLEASE CHECK PATH IS CORRECT"), vbCritical
End If
Else
MsgBox "PLEASE SELECT AN INVOICE NUMBER.", vbExclamation, "HYPERLINKING THE INVOICE NUMBER"
End If
End With
End If
With Sheets("INV")
Worksheets("INV").Activate
Worksheets("INV").Range("G13").Select
With ActiveSheet
ActiveWindow.SelectedSheets.PrintOut copies:=1
answer = MsgBox("DID THE INVOICE PRINT OK ?", vbInformation + vbYesNo, "INVOICE PRINT OK MESSAGE")
If answer = vbNo Then
Exit Sub
Else
Dim MyFile As String
MyFile = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR SCREEN SHOT PDF\" & Range("G13").Value & ".pdf"
If Dir(MyFile) <> "" Then Kill MyFile
Range("L4").Value = Range("L4").Value + 1
Range("G27:L36").ClearContents
Range("G46:G50").ClearContents
Range("L18").ClearContents
Range("G13").ClearContents
Range("G13").Select
ActiveWorkbook.Save
End If
End With
End With
End Sub