View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1808_] Rick Rothstein \(MVP - VB\)[_1808_] is offline
external usenet poster
 
Posts: 1
Default Getting <Title out of HTML source code

I'm not all that familiar with HTML source code... can there be more
than one <title, </title pair in a file? If no, then this function
will
return that single title...

Function GetTitle(TextToSearch As String) As String
GetTitle = Split(Split(TextToSearch, "<title", , vbTextCompare)(1), _
"</title", , vbTextCompare)(0)
End Function

If, on the other hand, there can be more than one, then this function
will
return a zero-based array containing all the found titles...

Function GetTitle(TextToSearch As String) As String()
Dim X As Long
Dim Titles() As String
Titles = Split(TextToSearch, "<title", , vbTextCompare)
For X = 1 To UBound(Titles)
Titles(X - 1) = Split(Titles(X), "</title", , vbTextCompare)(0)
Next
ReDim Preserve Titles(UBound(Titles) - 1)
GetTitle = Titles
End Function


Thanks. Would I just put beneathe the function then something
like .Cells(C:C) or something for it to put it into the column C?


I'm not sure I understand what you mean when you say "put beneath the
function"... it is a function (no different from something like Sin or Sqr),
you call it and use it results. Something like this for the single <title
occurrence...

.....
..... <<< Open file and get contents
..... <<< assume text is assigned to TextFromFile variable

Msgbox GetTitle(TextFromFile)

..... <<<rest of your code
.....

For the multi-occurrence of <title, you will need to assign the return from
the function to a dynamically declared array and then, as you would do with
any array, iterate that array to get each individual item in it.

Rick