LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default On Error

It's ok with me.

But if the user hits cancel when asked for the quotenumber, wouldn't you want
the code to stop?

Trim is built into excel's VBA. It should not cause an error.

So if you're getting an error message on this statement, it usually means that
you have an invalid reference in that workbook's project.

Open excel and your workbook
Open the VBE and select your workbook's project.
Then click on: Tools|References
Look for MISSING reference.

Uncheck that missing reference.

Then test your code. If it works ok, then go back to excel and save your
workbook.


oldjay wrote:

I got an error when I ran the routine at " If Trim(QuoteNumber) = "" Then"
it highlighted the "Trim " and said "Can't find project or library" It seems
to work when I commented it out.
Is that OK?

"Dave Peterson" wrote:

Option Explicit
Sub testme()

Dim TestStr As String
Dim Quote As String
Dim QuoteNumber As String
Dim PathsToTry As Variant
Dim pCtr As Long
Dim wkbk As Workbook
Dim myFileName As String
Dim FoundIt As Boolean

PathsToTry = Array("C:\quotes\", _
"\\SERVER3\Jobs\Estimate1\NEW_QUOT1\")

QuoteNumber = InputBox("...")

If Trim(QuoteNumber) = "" Then
Exit Sub 'user hit cancel
End If

FoundIt = False
For pCtr = LBound(PathsToTry) To UBound(PathsToTry)
myFileName = PathsToTry(pCtr) & QuoteNumber & ".xls"

TestStr = ""
On Error Resume Next
TestStr = Dir(myFileName)
On Error GoTo 0

If TestStr = "" Then
'wasn't found, keep looking
Else
FoundIt = True
Exit For
End If
Next pCtr

If FoundIt = False Then
MsgBox "It wasn't found!"
Exit Sub
End If

Set wkbk = Workbooks.Open(Filename:=myFileName)

MsgBox wkbk.FullName

End Sub


oldjay wrote:

I want to recall a file that if not on the C drive looks on the server

quotenumber = InputBox("Please enter QUOTE file name to recall", "X
Technologies LLC")

Quote = "C:\Quotes\" & quotenumber & ".XLS"

Quote = "\\SERVER3\Jobs\Estimate1\NEW_QUOT1\" & quotenumber & ".XLS"

Workbooks.Open Filename:=Quote


--

Dave Peterson
.


--

Dave Peterson
 
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
Error handling error # 1004 Run-time error [email protected] Excel Programming 3 May 20th 08 02:23 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Form Err.Raise error not trapped by entry procedure error handler [email protected] Excel Programming 1 February 8th 06 10:19 AM
Automation Error, Unknown Error. Error value - 440 Neo[_2_] Excel Programming 0 May 29th 04 05:26 AM


All times are GMT +1. The time now is 07:46 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"