Results 1 to 2 of 2

Thread: Advice on extracting First line of actual text in a word doc?

  1. #1

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935

    Advice on extracting First line of actual text in a word doc?

    Okay first of all thanks to those who reminded me of the open file syntax

    Heres my current problem

    I have managed to search for and extract the first line from each word document on a hdd.

    however a ms word doc puts alsorts of rubbish in with the actual text.

    what i need to be able to do is extract the first line of actual text from the document??

    Is there any known methods for doing this eg for reading a word document or will i have to manually code a trim function to go through and sort all the rubbish out??

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    If you are willing to open Word then it's fairly easy. One thing to remember about Word documents is that the first line may not be in a normal paragraph - it may be in a table.
    Code:
    Option Explicit
    Private wdApp As Word.Application
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Public Sub GetFirstText()
    
        wdApp.Documents.Open ("C:\MyDoc")
        wdApp.ActiveDocument.Paragraphs(1).Range.Select
        MsgBox wdApp.Selection
        wdApp.Quit
        
    End Sub
    
    Private Sub Command1_Click()
    
        GetFirstText
        
    End Sub
    
    Private Sub Form_Load()
    
        Dim hWnd As Long
        
        ' Find out if Word is already running
        hWnd = FindWindow("OpusApp", vbNullString)
        If hWnd = 0 Then
            Set wdApp = New Word.Application
        Else
            Set wdApp = Word.Application
        End If
    
    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width