On Error Resume Next not working (2010)

C

Clif McIrvin

Here's a code snippet that has worked for years under 2003:

strFullName = strPath & subPath & varBookName
Err.Clear
On Error Resume Next
Workbooks.Open FileName:=strFullName, _
UpdateLinks:=0 'do not update
Select Case Err.Number

Now, under 2010 if the file does not exist I get a dialog that displays
the filename as "not found, etc, etc." When I click on OK, the code
continues executing and does what I expect. Is there a setting change
on 2010 or something that I'm missing?
 
P

Per Jessen

I don't use 2010, but I would check how excel is set up to handle
errors:

In the VBA editor goto Tools > Options > General > Error Handling:
Select 'Break on Unhandled Errors'

Regards,
Per
 
S

Steve

Here's a code snippet that has worked for years under 2003:

    strFullName = strPath & subPath & varBookName
    Err.Clear
    On Error Resume Next
    Workbooks.Open FileName:=strFullName, _
        UpdateLinks:=0         'do not update
    Select Case Err.Number

Now, under 2010 if the file does not exist I get a dialog that displays
the filename as "not found, etc, etc."  When I click on OK, the code
continues executing and does what I expect.  Is there a setting change
on 2010 or something that I'm missing?

I would check to be sure you have turned off displaying messages to
the user
Application.DisplayAlerts = False

Steve
 
N

norie

Here's a code snippet that has worked for years under 2003:

    strFullName = strPath & subPath & varBookName
    Err.Clear
    On Error Resume Next
    Workbooks.Open FileName:=strFullName, _
        UpdateLinks:=0         'do not update
    Select Case Err.Number

Now, under 2010 if the file does not exist I get a dialog that displays
the filename as "not found, etc, etc."  When I click on OK, the code
continues executing and does what I expect.  Is there a setting change
on 2010 or something that I'm missing?

Cliff

Why not check if the file exists using Dir rather than using On Error?

If Dir(strFullName)<>"" Then
Set wbOpen = Workbooks.Open(FileName:=strFullName,
UpdateLinks:=0)
Else
Msgbox "File not found, check filename and path."
End If
 
C

Clif McIrvin

Here's a code snippet that has worked for years under 2003:

strFullName = strPath & subPath & varBookName
Err.Clear
On Error Resume Next
Workbooks.Open FileName:=strFullName, _
UpdateLinks:=0 'do not update
Select Case Err.Number

Now, under 2010 if the file does not exist I get a dialog that
displays
the filename as "not found, etc, etc." When I click on OK, the code
continues executing and does what I expect. Is there a setting change
on 2010 or something that I'm missing?

Cliff

Why not check if the file exists using Dir rather than using On Error?

If Dir(strFullName)<>"" Then
Set wbOpen = Workbooks.Open(FileName:=strFullName,
UpdateLinks:=0)
Else
Msgbox "File not found, check filename and path."
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top