Consulting

Results 1 to 2 of 2

Thread: .html/word document "parsing" question

  1. #1

    .html/word document "parsing" question

    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?


  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Here is one approach:
    [vba]
    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)
    Loop
    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"
    Else
    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
    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •