A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"ON ERROR GOTO"



 
 
Thread Tools Display Modes
  #1  
Old September 19th, 2003, 09:42 PM
Krappo
external usenet poster
 
Posts: n/a
Default "ON ERROR GOTO"

Hello ppls,

I need an Error Handler which looks like this:

Sub Macro1()

On Error Goto AAA
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
Exit Sub

AAA:
MsgBox "Book2 not Found"
On Error Goto BBB
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Exit Sub

BBB:
MsgBox "Book3 not Found"

End Sub

I know that there is no way I can repeat "On Error Goto _____" in one
procedure.
Please show me how....

Secondly, how to write a ***msgbox so that it display as I type (line by
line in one single message).

Thanks in advance.

Krappo.


  #2  
Old September 19th, 2003, 10:16 PM
Ed
external usenet poster
 
Posts: n/a
Default "ON ERROR GOTO"

Krappo,

What you need to do is seperate the 2 Open calls into
different procedures. Something like this:

Sub openBook2()

On Error Goto AAA
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
Exit Sub

AAA:
MsgBox "Book2 not Found"
openBook3

End Sub

Sub openBook3()

On Error Goto BBB
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Exit Sub

BBB:
MsgBox "Book3 not Found"

End Sub

I don't under your second question: "write a ***msgbox so
that it display as I type (line by line in one single
message)."


-----Original Message-----
Hello ppls,

I need an Error Handler which looks like this:

Sub Macro1()

On Error Goto AAA
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
Exit Sub

AAA:
MsgBox "Book2 not Found"
On Error Goto BBB
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Exit Sub

BBB:
MsgBox "Book3 not Found"

End Sub

I know that there is no way I can repeat "On Error Goto

_____" in one
procedure.
Please show me how....

Secondly, how to write a ***msgbox so that it display as

I type (line by
line in one single message).

Thanks in advance.

Krappo.


.

  #3  
Old September 19th, 2003, 11:56 PM
Krappo
external usenet poster
 
Posts: n/a
Default "ON ERROR GOTO"

Thank you Ed,

For the second question, I have too many words in my message box eg.

msgbox "The book you've requested not found. Either you have miss placed
the book or such book is not present"

So, I wanted to make it display in popup message looks like this:-

The book you've requested no found.
Either you have miss placed the book
or such book is not present.

Krappo.


  #4  
Old September 20th, 2003, 12:06 AM
Dan E
external usenet poster
 
Posts: n/a
Default "ON ERROR GOTO"

Krappo,

MsgBox Prompt:="The book you've requested no found." & _
vbCrLf & "Either you have missplaced the book" & _
vbCrLf & "or such book is not present."

the vbcrlf is carriage return line feed (ie enter)

Dan E

"Krappo" - wrote in message ...
Thank you Ed,

For the second question, I have too many words in my message box eg.

msgbox "The book you've requested not found. Either you have miss placed
the book or such book is not present"

So, I wanted to make it display in popup message looks like this:-

The book you've requested no found.
Either you have miss placed the book
or such book is not present.

Krappo.




  #5  
Old September 20th, 2003, 12:21 AM
Krappo
external usenet poster
 
Posts: n/a
Default "ON ERROR GOTO"

Thanks Dan E,

That was wonderfull! I appreciate your help and I really looking for
that solutions.

Thanks to both of you, Ed who have settled my first question and to
you for the second questions.

Best wish to both of you.
Krappo.



  #6  
Old September 20th, 2003, 03:15 AM
J.E. McGimpsey
external usenet poster
 
Posts: n/a
Default "ON ERROR GOTO"

One way:


Public Sub Macro1()
On Error GoTo AAA
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
On Error GoTo BBB
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Exit Sub
AAA:
MsgBox "Book2 not found"
Resume Next
BBB:
MsgBox "Book3 not found"
Resume Next
End Sub



In article , "Krappo" -
wrote:

Hello ppls,

I need an Error Handler which looks like this:

Sub Macro1()

On Error Goto AAA
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
Exit Sub

AAA:
MsgBox "Book2 not Found"
On Error Goto BBB
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Exit Sub

BBB:
MsgBox "Book3 not Found"

End Sub

I know that there is no way I can repeat "On Error Goto _____" in one
procedure.
Please show me how....

Secondly, how to write a ***msgbox so that it display as I type (line by
line in one single message).

Thanks in advance.

Krappo.


  #7  
Old September 20th, 2003, 05:34 AM
Harlan Grove
external usenet poster
 
Posts: n/a
Default "ON ERROR GOTO"

"J.E. McGimpsey" wrote...
One way:

Public Sub Macro1()
On Error GoTo AAA
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
On Error GoTo BBB
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Exit Sub


Doesn't this open both Book2 and Book3 when they both exist? Not what the
OP's macro does.

AAA:
MsgBox "Book2 not found"
Resume Next
BBB:
MsgBox "Book3 not found"
Resume Next
End Sub


When error trapping is unnecessary, it should be avoided.

Sub foo()
If Dir("C:\dir\dir\book2.xls") "" Then
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
Else
MsgBox "Book2 not found"
If Dir("C:\dir\dir\book3.xls") "" Then
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Else
MsgBox "Book3 not found"
End If
End If
End Sub


  #8  
Old September 20th, 2003, 06:06 AM
J.E. McGimpsey
external usenet poster
 
Posts: n/a
Default "ON ERROR GOTO"

Thanks for the correction, Harlan - I missed the Exit Sub after the
first attempt.

When error trapping is unnecessary, it should be avoided.


I agree with you, and almost none of my coding makes extensive use
of error trapping, but I've found that's not a universal meme.


In article ,
"Harlan*Grove" wrote:

Doesn't this open both Book2 and Book3 when they both exist? Not what the
OP's macro does.



AAA:
MsgBox "Book2 not found"
Resume Next
BBB:
MsgBox "Book3 not found"
Resume Next
End Sub


When error trapping is unnecessary, it should be avoided.

Sub foo()
If Dir("C:\dir\dir\book2.xls") "" Then
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
Else
MsgBox "Book2 not found"
If Dir("C:\dir\dir\book3.xls") "" Then
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Else
MsgBox "Book3 not found"
End If
End If
End Sub

  #9  
Old September 20th, 2003, 08:32 PM
Ed
external usenet poster
 
Posts: n/a
Default "ON ERROR GOTO"

So J.E and Harlan,

Was my code a simple and reasonable solution?:
What you need to do is seperate the 2 Open calls into
different procedures. Something like this:

Sub openBook2()

On Error Goto AAA
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
Exit Sub

AAA:
MsgBox "Book2 not Found"
openBook3

End Sub

Sub openBook3()

On Error Goto BBB
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Exit Sub

BBB:
MsgBox "Book3 not Found"

End Sub

-----Original Message-----
Thanks for the correction, Harlan - I missed the Exit

Sub after the
first attempt.

When error trapping is unnecessary, it should be

avoided.

I agree with you, and almost none of my coding makes

extensive use
of error trapping, but I've found that's not a universal

meme.


In article ,
"Harlan Grove" wrote:

Doesn't this open both Book2 and Book3 when they both

exist? Not what the
OP's macro does.



AAA:
MsgBox "Book2 not found"
Resume Next
BBB:
MsgBox "Book3 not found"
Resume Next
End Sub


When error trapping is unnecessary, it should be

avoided.

Sub foo()
If Dir("C:\dir\dir\book2.xls") "" Then
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
Else
MsgBox "Book2 not found"
If Dir("C:\dir\dir\book3.xls") "" Then
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Else
MsgBox "Book3 not found"
End If
End If
End Sub

.

  #10  
Old September 20th, 2003, 10:20 PM
Krappo
external usenet poster
 
Posts: n/a
Default "ON ERROR GOTO"

Hi,

My appreciations and many thanks to all of you for assisting
me on this topic.

Best wish,
Krappo.

"Ed" wrote in message
...
So J.E and Harlan,

Was my code a simple and reasonable solution?:
What you need to do is seperate the 2 Open calls into
different procedures. Something like this:

Sub openBook2()

On Error Goto AAA
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
Exit Sub

AAA:
MsgBox "Book2 not Found"
openBook3

End Sub

Sub openBook3()

On Error Goto BBB
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Exit Sub

BBB:
MsgBox "Book3 not Found"

End Sub

-----Original Message-----
Thanks for the correction, Harlan - I missed the Exit

Sub after the
first attempt.

When error trapping is unnecessary, it should be

avoided.

I agree with you, and almost none of my coding makes

extensive use
of error trapping, but I've found that's not a universal

meme.


In article ,
"Harlan Grove" wrote:

Doesn't this open both Book2 and Book3 when they both

exist? Not what the
OP's macro does.



AAA:
MsgBox "Book2 not found"
Resume Next
BBB:
MsgBox "Book3 not found"
Resume Next
End Sub

When error trapping is unnecessary, it should be

avoided.

Sub foo()
If Dir("C:\dir\dir\book2.xls") "" Then
Workbooks.Open Filename:="C:\dir\dir\book2.xls"
Else
MsgBox "Book2 not found"
If Dir("C:\dir\dir\book3.xls") "" Then
Workbooks.Open Filename:="C:\dir\dir\book3.xls"
Else
MsgBox "Book3 not found"
End If
End If
End Sub

.





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


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


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