I'm trying to do the following with the code below:
1. If the file is not in your My Documents folder than goto errhandler and a message box pops up asking you to retry or cancel.
2. When the user clicks retry it goes back and trys again but if the file still isn't there a runtime error 1004 occurs.
I want it to continue to loop when the user presses retry or until cancel is pressed. I've been trying with the code below but no luck. Any suggustions?
Thanks!
1. If the file is not in your My Documents folder than goto errhandler and a message box pops up asking you to retry or cancel.
2. When the user clicks retry it goes back and trys again but if the file still isn't there a runtime error 1004 occurs.
I want it to continue to loop when the user presses retry or until cancel is pressed. I've been trying with the code below but no luck. Any suggustions?
Thanks!
Code:
Public Function AddITARPicOffloadAnalysis()
Dim xlApp As Object
Dim wb As Object
Dim ws As Object
Dim Lastrow As Long
Dim objFolders As Object
Set xlApp = CreateObject("Excel.Application")
With xlApp
On Error GoTo ErrHandler
Do
Set objFolders = CreateObject("WScript.Shell").SpecialFolders
Set wb = .Workbooks.Open(objFolders("mydocuments") & "\OffloadAnalysis.xlsx")
Set ws = wb.Sheets(1)
'Code below counts the cells with data and selects the last empty cell
Lastrow = ws.UsedRange.Rows.Count
Blankcell = Lastrow + 1
ws.Cells(Blankcell, "I").Select
ws.pictures.insert (D:\Sample.png)
.Visible = True
LinkToFile = False
SaveWithDocument = True
wb.Close , SaveChanges:=True
Set xlApp = Nothing
Exit Function
ErrHandler:
i = MsgBox("Make sure that OffloadAnalysis.xlsx is in the following location:" & objFolders("mydocuments"), vbRetryCancel, "File Location")
Loop While i = vbRetry
If i = vbCancel Then
End If
End With
End Function