Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 8th, 2005, 09:00 AM
Registered User
 
Join Date: Apr 2005
Location: Bristol, , United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error Handling

Im having trouble effectively handling errors during run time. The problem is that the vba error handler will only run once. So if you're trying to trap errors that occur as part of a loop you can call your error sequence once but the second error causes a run time error and fails to continue past the warning message.

The details;
- In my macro Im saving files to particular locations. I wrote an error trap just incase the relivant folder didnt exist or another user was already accessing the file.
- If an error occurs then my macro makes a log of it before clearing the error log and continuing through the loop.
- The macro works great until yo uencounter the error for the second time, where you get a run-time error and it doesnt want to call my error handling routine.

Anybody have any ideas / help please?

Thanks,
Dave.

Danger shines like sunshine in a brave mans eyes!
 
Old August 8th, 2005, 10:40 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Bournemouth, Dorset, United Kingdom.
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

using the resume next in the following code will form the basis of your answer hopefully.

cheers

Matt
---------------------------------------

Sub myErrorTrap()
Dim myError As String
Dim myLoop As Integer
On Error GoTo myErrorMsg
myLoop = 0
Do Until ActiveCell.Value = ""

    myLoop = myLoop + 1
    '...code goes here

    GoTo myNoError

myErrorMsg:
    myError = myError & "Loop Line no:" & myLoop & " - " & Error$ & "," & Chr$(13)
Resume Next

myNoError:
    ActiveCell.Offset(1, 0).Select
Loop

If IsNull(myError) Then
    GoTo myExitSub
Else
    MsgBox (myError)
End If

myExitSub:

End Sub

--------------------------------
 
Old August 18th, 2005, 03:54 AM
Registered User
 
Join Date: Apr 2005
Location: Bristol, , United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ahhh...so simple but SO useful! Thanks very much, that was just what I needed.
Even the 2 big books (Wrox included!) and the help files couldnt come up with that answer.

Cheers,
Dave.
:D

Danger shines like sunshine in a brave mans eyes!




Similar Threads
Thread Thread Starter Forum Replies Last Post
error handling Abhinav_jain_mca General .NET 5 December 21st, 2005 01:12 AM
Error Handling twbit BOOK: ASP.NET Website Programming Problem-Design-Solution 1 May 3rd, 2005 09:18 PM
Error handling Hudson40 Access VBA 2 February 11th, 2005 05:32 AM
Error Handling zaeem Classic ASP Basics 2 November 14th, 2003 10:42 AM
Error handling ! ittorget Classic ASP Professional 2 November 14th, 2003 09:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.