Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default Cant find workbook

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Cant find workbook

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Cant find workbook

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Cant find workbook

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
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
Find a value in a workbook VBA jlclyde Excel Discussion (Misc queries) 5 January 20th 10 04:33 PM
Find cell in Excel2000 workbook with link from another workbook? Mark4mmx Excel Discussion (Misc queries) 1 October 8th 08 12:55 PM
How can I find value from another workbook Jaan Excel Worksheet Functions 0 November 30th 06 08:50 AM
Find within Workbook. Matt Carter Excel Discussion (Misc queries) 2 August 3rd 05 07:40 PM
"Find" in workbook Chuck Davis Excel Discussion (Misc queries) 5 December 10th 04 12:05 AM


All times are GMT +1. The time now is 10:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"