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. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
"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
|
|||
|
|||
"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
|
|||
|
|||
"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
|
|||
|
|||
"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
|
|||
|
|||
"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
|
|||
|
|||
"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
|
|||
|
|||
"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
|
|||
|
|||
"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
|
|||
|
|||
"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
|
|||
|
|||
"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 | |
|
|