View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default replace VBA run-time error message with custom message

You don't need the () in the workbooks.open line:

If testStr = "" Then
Call NotAvailable
Else
Workbooks.Open "C:\Contract Templates\BB-Pup-Chassis-2006_R1C0.xls"
End If

Dave Peterson wrote:

If testStr = "" Then
Call NotAvailable
Else
Workbooks.Open ("C:\Contract Templates\BB-Pup-Chassis-2006_R1C0.xls")
End If

BEEJAY wrote:

Thanks for your response.
I now have the following, but it comes up with
Compile error - Else without IF
What am I missing here?

Dim testStr As String
testStr = ""
On Error Resume Next
testStr = Dir("C:\Contract Templates\BB-Pup-Chassis-2006_R1C0.xls")
On Error GoTo 0

If testStr = "" Then Call NotAvailable
Else: Workbooks.Open ("C:\Contract
Templates\BB-Pup-Chassis-2006_R1C0.xls")
End If
Thank-you

"Dave Peterson" wrote:

If I don't have many to check, I do it inline.

dim testStr as string
.....
teststr = ""
on error resume next
teststr = dir("C:\Contracts\BB-Pup-Chassis-2006_R0C0.xls")
on error goto 0

if teststr = "" then
'not found
else
'was found
end if

Watch you're typing, too. You have a vertical bar instead of a backslash in
that first line.


BEEJAY wrote:

SLOWLY waking up this lovely Friday:
Now have:
If Exists("C:\Contracts|BB-Pup-Chassis-2006_R0C0.xls") Then
Workbooks.Open ("C:\Contracts\BB-Pup-Chassis-2006_R0C0.xls")
Else: Call NotAvailable

the 1st line comes up with a complie error - Sub or Function not defined.
Now I am truly Stuck.
Help Please.

End Sub

"BEEJAY" wrote:

Further:
The code that selects the files are as per this sample:
Sub BB_Chassis()
Workbooks.Open ("C:\Contracts\BB-Pup-Chassis-2006_R0C0.xls")
End Sub

I wondering if an If-Then_Else could somehow be used.
If Exits, then select/open Work Book
Else, Call Message
Something like that?



"BEEJAY" wrote:

Used J-Walks Menu maker to create menu of frequently used Spread-Sheets.
This add-in will be sent to all our salesmen.
The menu lists ALL of the available Sp.Sheets, BUT not every salesman gets
every Sp.Sheet.
When a non-existant Sp.Sheet is selected from menu, error message pops up:
"C:\ .................... (file Name), could not be found. Check spelling
...............

I'd like to NOT have this message come up, but replace it with a custom
message,
something like: The requested file is not on your available list. Please
select the correct template.
Therefo Can I deactivate/delete the VBA message? If yes, How?
How can I program in a message that tests for the requested Sp. Sheet, and
selects the Sp. Sheet, if exists, or else comes up with my custom message?
I hope this makes sense.
Help!!


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson