Kill my file

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. 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


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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Sorry my mistaek
The extra kill file or the likes will need to look at value in cell L4 then delete it from here
C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES
 
Upvote 0
Can ssomething be done like this.

Rich (BB code):
   Dim DeletePdf As String
      DeletePdf = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR SCREEN SHOT PDF\" & Range("L4").Value & ".pdf"
    If Dir(DeletePdf) <> "" Then .Delete
 
Upvote 0

Forum statistics

Threads
1,215,072
Messages
6,122,966
Members
449,094
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top