View Full Version : .html/word document "parsing" question

01-07-2007, 02:54 PM
ok im new to this so sorry if this question is simple/ trivial but im wondering if there is a program which would search through text or .html files for a certain string then record say the next 100 chars and save it to a file, is there such a program?

01-12-2007, 04:27 PM
Here is one approach:

Option Explicit
Sub GenericCode()
Dim strSearchString As String
Dim mbr As VBA.VbMsgBoxResult
Dim strFilePath As String
Dim intFileNumber As Integer
Dim strFileText As String
Dim blnFnd As String
strSearchString = VBA.InputBox("Enter Search String Here:", "Enter Search String")
If VBA.LenB(strSearchString) = 0 Then Exit Sub
mbr = MsgBox("Match case?", vbQuestion + vbMsgBoxSetForeground + vbYesNoCancel, "Select Matching Method")
If mbr = vbCancel Then Exit Sub
strFilePath = GetFile
If VBA.LenB(strFilePath) = 0 Then Exit Sub
intFileNumber = VBA.FreeFile
Open strFilePath For Input As #intFileNumber
Do While Not VBA.EOF(intFileNumber)
strFileText = strFileText & Input(1, #intFileNumber)
Close #intFileNumber
If mbr = vbYes Then
strFileText = VBA.LCase$(strFileText)
strSearchString = VBA.LCase$(strSearchString)
End If
blnFnd = (VBA.InStrB(1, strFileText, strSearchString, vbTextCompare) > 0)
If blnFnd Then
VBA.MsgBox "Found it.", vbInformation + vbMsgBoxSetForeground, "Item Found"
VBA.MsgBox "Couldn't find it.", vbExclamation + vbMsgBoxSetForeground, "Item Not Found"
End If
End Sub
Private Function GetFile() As String
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Title = "Select file to search"
If fd.Show = 0 Then Exit Function
GetFile = fd.SelectedItems(1)
End Function