Thread: Error trapping?
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
IanC[_2_] IanC[_2_] is offline
external usenet poster
 
Posts: 157
Default Error trapping?

I need to look for a specific text string within a spreadsheet then, if it
isn't found, look for another text string.

The problem I have with the existing code is that if the 1st search string
(SD) isn't found, it doesn't look for the second string. If is DOES find the
first string, it goes on to look for the second string anyway (currently
commented out). This wouldn't be a problem if the second string exists, but
if it doesn't then the following doesn't execute.

I know I'm going about this the wrong way, but I'm not sure how to remedy
the situation. Any ideas?

My code is below:

Private Sub CheckVersion(sTPPath, sUpdRoot, dVer, sVerRep, sCurPath,
sUpdFile)
Dim lLoc As Long
Dim dNewVer As Double
' Checks version of existing template
With Application
.EnableEvents = False
Workbooks.Open Filename:= _
sTPPath & "\" & sUpdRoot & ".xlt", _
UpdateLinks:=0, Editable:=True
On Error GoTo noSD
.Cells.Find(What:="SD", After:=.ActiveCell, LookIn:=xlValues,
LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
' ***** Second string find to go here *****
' On Error GoTo noSD
' .Cells.Find(What:=sUpdRoot & " v", After:=.ActiveCell,
LookIn:=xlValues, LookAt:= _
' xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
' False).Activate
lLoc = InStrRev(.ActiveCell.Value, "v")
dVer = Val(Right(.ActiveCell.Value, Len(.ActiveCell.Value) - lLoc))
sUpdFile = Dir(sCurPath & "\" & sUpdRoot & "*.xlt")
sUpdFile = Left(sUpdFile, Len(sUpdFile) - 4)
lLoc = InStrRev(sUpdFile, "v")
dNewVer = Val(Right(sUpdFile, Len(sUpdFile) - lLoc))
If dNewVer <= dVer Then
sVerRep = "Failure - Update version is the same or older than
existing template"
Else
sVerRep = "Current version is " & dVer
End If
.Visible = True
.EnableEvents = True
End With
GoTo subend
noSD:
sVerRep = "Failure - Unable to update from this version"
subend:
End Sub


Many thanks.

---
Ian
---