Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The below code opens the workbook in Textbox6.
Workbooks.Open TextBox6.Value If the workbook is not located, I get a VBA error, instead I would like a messagebox to popup and say "Workbook not found." and then exit sub. Thanx Todd Huttenstine |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this:
On Error Resume Next 'disable error myBook =TextBox6.Value Set testOpened = Workbooks.Open(myBook) If Not IsObject(testOpened) Then MsgBox myBook & " not found" End If On Error GoTo 0 'reset error ....Chris "Todd Huttenstine" wrote in message ... The below code opens the workbook in Textbox6. Workbooks.Open TextBox6.Value If the workbook is not located, I get a VBA error, instead I would like a messagebox to popup and say "Workbook not found." and then exit sub. Thanx Todd Huttenstine |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here are a couple ways to trap the error:
Sub Way1() If Dir(TextBox6.Value) < "" Then Workbooks.Open TextBox6.Value Else MsgBox "File cannot be found" Exit Sub End If ''Continues.... End Sub Sub Way2() On Error Resume Next Workbooks.Open TextBox6.Value If Err.Number < 0 Then MsgBox "Error opening workbook. The specific" & _ "Excel error message was " & Err.Description Exit Sub End If ''Continues.... End Sub -- Jim Rech Excel MVP |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Error GoTo e
Workbooks.Open TextBox6.Value Exit Sub e: MsgBox "Workbook not found." "Todd Huttenstine" wrote in message ... The below code opens the workbook in Textbox6. Workbooks.Open TextBox6.Value If the workbook is not located, I get a VBA error, instead I would like a messagebox to popup and say "Workbook not found." and then exit sub. Thanx Todd Huttenstine |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Find a value in a workbook VBA | Excel Discussion (Misc queries) | |||
Find cell in Excel2000 workbook with link from another workbook? | Excel Discussion (Misc queries) | |||
How can I find value from another workbook | Excel Worksheet Functions | |||
Find within Workbook. | Excel Discussion (Misc queries) | |||
"Find" in workbook | Excel Discussion (Misc queries) |