Get Last Value


Home           Programming       Favorites      

VBA sometimes returns the entire pathname for a property.

This function will get the last value.  It will return TopicIndex.htm from the string below.

String file:///C:/Documents and Settings/rdahl/My Documents/My Web Sites/AutomationInformation/Programming/MicrosoftVBA/TopicIndex.htm

Function GetLastValue( _
strFind As String, _
strText As String) _
As String
  intStartPoint = _
  GetLastIndexOf(strFind, strText)
  GetLastValue = _
  Mid(strText, intStartPoint + 1, Len(strText))
  
  Exit Function
errHandler1:
   MsgBox _
   "Err.Number:      " & Err.Number & vbCrLf & _
   "Err.Description: " & Err.Description, _
   vbCritical, "GetLastIndexOf Function " & _
   "terminated because of Fatal Error."
End Function

It could be called with:

Sub callGetValue()
Dim intLastIndex As Integer
Dim strSearchFor As String
Dim strSearchIn As String
Dim strShortName As String

strSearchFor = "/"
strSearchIn = _
"file:///C:/Documents and Settings/rdahl" & _
"/My Documents/My Web Sites" & _
"/AutomationInformation" & _
"/Programming/MicrosoftVBA/TopicIndex.htm"

strShortName = _
GetLastValue(strSearchFor, strSearchIn)

End Sub