VBA OnError based on error code

anichols

Board Regular
Joined
Mar 11, 2021
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hello all,


I have some code that has a successful OnError code that provides a message indicating that the file is currently in use by another user (error code 75 would normally populate). What I am trying to do however, is put an if statement in the error code so that if the error isn't caused by error code 75 then an alternative user friendly message will appear. As an example, if the file is not located in the correct file path error code 53 file not found would appear.

Any assistance would be greatly appreciated.
Here is my code for reference:
VBA Code:
Sub MoveEm_Redxx() 'Moving static files Off P Drive
    Dim Itemx As Variant
    Dim L As Long
    'On Error GoTo grr
    'Initial Variable levels
    Itemx = 0
    L = 65
    ''''''''''''''''''
    
    Application.Run "Pro.XPro01"
    Itemx = Itemx + 1: L = L + 1
    Name Sheets(1).Range("B66").Value As _
    Sheets(1).Range("E66").Value
    
    Application.Run "Pro.XPro02"
    Itemx = Itemx + 1: L = L + 1
    Name Sheets(1).Range("B67").Value As _
    Sheets(1).Range("E67").Value
    
    Application.Run "Pro.XPro03"
    Itemx = Itemx + 1: L = L + 1
    Name Sheets(1).Range("B68").Value As _
    Sheets(1).Range("E68").Value

    Application.Run "Pro.XPro04"
    Itemx = Itemx + 1: L = L + 1
    Name Sheets(1).Range("B69").Value As _
    Sheets(1).Range("E69").Value

    
    Exit Sub
grr:
    Error.Information.Caption = "The workbook located here:" & vbNewLine & Sheets(1).Range("B" & L).Value & vbNewLine & " Is currently in use by another user. Please ask them to exit then press continue..."
    Error.Show 'can you have the resume or resume next in the two different buttons of the userform??? essentially to try again or to skip to the next line of code.
    Resume
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi anichols,

maybe Select Case Err.Number and use the cases (Case 75, Case 53, Case Else)

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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