I am using the following code to format an excel file:
However, I am trying to tackle the problem if a user tries to import a file again after it has already been formatted. The main issue is the picture object would no longer exist. How can I structure the code to deal with that?
If picture 1 exist, delete. If not then move on.
Code:
Set xl = New Excel.Application
Set wb = xl.Workbooks.Open(strfile)
Set ws = wb.Sheets("Sheet0")
'delete header information
Set r = ws.Range("A:K").Find("QTY", lookin:=xlValues)
ws.Shapes.Range(Array("Picture 1")).Delete
If r.Row <> 1 Then
ws.Range("A1", r.Offset(-1)).EntireRow.Delete xlShiftUp
End If
'delete footer up to and including total
Set r = ws.Range("B:K").Find("Total", lookin:=xlValues)
With ws
.Rows(r.Row & ":" & .Rows.Count).Delete
End With
However, I am trying to tackle the problem if a user tries to import a file again after it has already been formatted. The main issue is the picture object would no longer exist. How can I structure the code to deal with that?
If picture 1 exist, delete. If not then move on.