Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default On Error action inconsistent

Through VBA, I enabling the use to add another worksheet and and change it's
name. I'm hoped to use the "On Error" trapping to continue looping asking
for valide worksheet name. My problem is that the error is trapped only
once. The second time around the error no longer trapped. What's the
correct way to use "On Error" to achieve my goal? Here's the code. Thanks
- Pat

Sub AddWorkSheet()
Dim vResponse As Variant

Sheet1.Copy After:=Sheets(Sheets.Count)

On Error GoTo BadName:
BadName:
vResponse = Trim(InputBox("New worksheet name? ", , ActiveSheet.Name))
If vResponse < "" Then
ActiveSheet.Name = vResponse
End If

On Error GoTo 0
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default On Error action inconsistent

Once an error has been encountered, error trapping is turned off until
the procedure ends (End Sub or Exit Sub) or until a Resume or Resume
Next statement is encountered. When an error is encountered, VBA
executes in "error mode" and no additional errors are trapped until a
Resume statement resets VBA out of "error mode" and back to "normal
mode". Try something like


Sub AddWorkSheet()
On Error GoTo ErrHandler
' your existing code here
ResumePoint:
Exit Sub
ErrHandler:
Resume ResumePoint
End Sub

The "Goto" when used with "On Error" doesn't work the same way as a
normal Goto.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sun, 19 Oct 2008 12:49:00 -0700, Dreiding
wrote:

Through VBA, I enabling the use to add another worksheet and and change it's
name. I'm hoped to use the "On Error" trapping to continue looping asking
for valide worksheet name. My problem is that the error is trapped only
once. The second time around the error no longer trapped. What's the
correct way to use "On Error" to achieve my goal? Here's the code. Thanks
- Pat

Sub AddWorkSheet()
Dim vResponse As Variant

Sheet1.Copy After:=Sheets(Sheets.Count)

On Error GoTo BadName:
BadName:
vResponse = Trim(InputBox("New worksheet name? ", , ActiveSheet.Name))
If vResponse < "" Then
ActiveSheet.Name = vResponse
End If

On Error GoTo 0
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default On Error action inconsistent

Chip,

THank you. This takes care of it.
- Pat

"Chip Pearson" wrote:

Once an error has been encountered, error trapping is turned off until
the procedure ends (End Sub or Exit Sub) or until a Resume or Resume
Next statement is encountered. When an error is encountered, VBA
executes in "error mode" and no additional errors are trapped until a
Resume statement resets VBA out of "error mode" and back to "normal
mode". Try something like


Sub AddWorkSheet()
On Error GoTo ErrHandler
' your existing code here
ResumePoint:
Exit Sub
ErrHandler:
Resume ResumePoint
End Sub

The "Goto" when used with "On Error" doesn't work the same way as a
normal Goto.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sun, 19 Oct 2008 12:49:00 -0700, Dreiding
wrote:

Through VBA, I enabling the use to add another worksheet and and change it's
name. I'm hoped to use the "On Error" trapping to continue looping asking
for valide worksheet name. My problem is that the error is trapped only
once. The second time around the error no longer trapped. What's the
correct way to use "On Error" to achieve my goal? Here's the code. Thanks
- Pat

Sub AddWorkSheet()
Dim vResponse As Variant

Sheet1.Copy After:=Sheets(Sheets.Count)

On Error GoTo BadName:
BadName:
vResponse = Trim(InputBox("New worksheet name? ", , ActiveSheet.Name))
If vResponse < "" Then
ActiveSheet.Name = vResponse
End If

On Error GoTo 0
End Sub


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
inconsistent error message DJ in KC Excel Discussion (Misc queries) 3 February 12th 09 05:10 AM
Inconsistent error Stuart[_19_] Excel Programming 5 December 11th 04 04:43 PM
OLE action error thru automation Ste[_2_] Excel Programming 3 June 4th 04 09:01 AM
Action on Error No Name Excel Programming 2 February 27th 04 06:57 PM
Action on error Mike Excel Programming 2 February 27th 04 06:08 PM


All times are GMT +1. The time now is 11:33 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"