Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Error trapping don't work

Hi all,

A colleague at work has an xl file that is linked to about 10 other
password-protected files over a winNT network. He want those files opening
without having to laboriously type in passwords in order to update his
master copy. The code below does work (it's behind a third file called
CodeFile.xls, but when i attempt to error trap I receive the usual Debug |
End |Help dialog box. Please can someone help as the vba is useless without
knowing which, if any, files failed to open (i.e. cos they were moved,
changed, deleted by other users).

Private Sub CommandButton1_Click()
On Error GoTo ErrorHandler

Workbooks.Open Filename:="blah\blah\Link.xls", updateLinks:=3, _
password:="gollum"
Workbooks.Open Filename:="blah\Master.xls", updateLinks:=3

Workbooks("Link.xls").Close

Exit Sub

ErrorHandler:
Select Case Err.Number

Case 1004
MsgBox "The file Could not be found", vbOKOnly + vbCritical, "Error"

Case Else
MsgBox (Err.Number & Err.Description)
End Select
Resume Next

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error trapping don't work

I couldn't get the Debug window to pop up while stepping thru the code
you posted. An error does occur when it hits the first Workbook.Open
line and it drops down to the errorhandler, executes the Case 1004
msgbox. At that point the Resume Next stmt sends the code to the 2nd
Workbook.Open line (Master.xls)

It may be due to how you're directing the code with the Resume Next
statement. It may also help to reset the error condition using On Error
Goto 0 such as:

Case Else
MsgBox (Err.Number & Err.Description)
End Select
On Error GoTo 0
Resume Next

Set a break point in your code by clicking on a line and then go to the
Debug menu and choose Toggle Breakpoint. Then go to your workbook and
click on Commandbutton1 to start the macro, which will then be stopped
at the break point. Then use the F8 key to execute one line of code at
a time to see exactly what the code is doing.


HTH


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Error trapping don't work

Hi Paul,

Make sure you haven't selected "Break on all errors" via Tools | Options,
General tab in the VBE.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Paul Wagstaff wrote:
Hi all,

A colleague at work has an xl file that is linked to about 10 other
password-protected files over a winNT network. He want those files
opening without having to laboriously type in passwords in order to
update his master copy. The code below does work (it's behind a third
file called CodeFile.xls, but when i attempt to error trap I receive
the usual Debug | End |Help dialog box. Please can someone help as
the vba is useless without knowing which, if any, files failed to
open (i.e. cos they were moved, changed, deleted by other users).

Private Sub CommandButton1_Click()
On Error GoTo ErrorHandler

Workbooks.Open Filename:="blah\blah\Link.xls", updateLinks:=3, _
password:="gollum"
Workbooks.Open Filename:="blah\Master.xls", updateLinks:=3

Workbooks("Link.xls").Close

Exit Sub

ErrorHandler:
Select Case Err.Number

Case 1004
MsgBox "The file Could not be found", vbOKOnly + vbCritical, "Error"

Case Else
MsgBox (Err.Number & Err.Description)
End Select
Resume Next

End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Error trapping don't work

Tools Options General Error Trapping Break on Unhandled Errors

did the trick.

zzz..! Thanks anyway!
Paul.

"btadams " wrote in message
...
I couldn't get the Debug window to pop up while stepping thru the code
you posted. An error does occur when it hits the first Workbook.Open
line and it drops down to the errorhandler, executes the Case 1004
msgbox. At that point the Resume Next stmt sends the code to the 2nd
Workbook.Open line (Master.xls)

It may be due to how you're directing the code with the Resume Next
statement. It may also help to reset the error condition using On Error
Goto 0 such as:

Case Else
MsgBox (Err.Number & Err.Description)
End Select
On Error GoTo 0
Resume Next

Set a break point in your code by clicking on a line and then go to the
Debug menu and choose Toggle Breakpoint. Then go to your workbook and
click on Commandbutton1 to start the macro, which will then be stopped
at the break point. Then use the F8 key to execute one line of code at
a time to see exactly what the code is doing.


HTH


---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Trapping gazza67[_2_] Excel Discussion (Misc queries) 2 September 6th 07 06:11 PM
Trapping #VALUE! error RhysPieces Excel Discussion (Misc queries) 6 August 22nd 07 03:13 AM
error trapping flow23 Excel Discussion (Misc queries) 3 April 13th 06 04:51 PM
Error Trapping Neil Excel Programming 1 January 5th 04 04:38 PM
error trapping libby Excel Programming 5 November 25th 03 10:57 PM


All times are GMT +1. The time now is 08:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"