Results 1 to 2 of 2

Thread: How can i extract text from a word document TextBox

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    5

    How can i extract text from a word document TextBox

    i have been working on word Document files.

    each document has same text format.

    i m using the code below to extract text from it,



    Code:
     
    
    Dim sFileName As String 'Name of files within the folder will be stored 
    Dim i As Integer 'This will count the files read***
    Dim wrd As Word.Application
    Dim wrdCount As Long 'Number of characters within the file
        'Get the first file with extension "DOC"  ***
                    sFileName = Dir$("C:\Virology\*.DOC") '***
        Do While sFileName <> "" '***
                Set wrd = New Word.Application 'Create obj of word application
                wrd.Visible = False
                wrd.Documents.Open "C:\Virology\" & sFileName
                wrdCount = wrd.Documents(1).Characters.Count
               Text1.Text = Text1.Text & vbCrLf & i & wrd.Documents(1).Range(0, wrdCount).Text
                wrd.Documents(1).Close
                Set wrd = Nothing
               sFileName = Dir$ '***
               i = i + 1
        Loop




    This works good for all the characters in the document but the problem rises when word textbox appears in the document.
    Attached Files Attached Files

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: How can i extract text from a word document TextBox

    I downloaded your document and created the following two macros in it. When you run abd() it prints the contents of the textboxes in the Immediate window. I guess you'll want to do something about the formatting, but I think this is the start of what you want to do.

    VB Code:
    1. Sub abd()
    2.     Dim s As Shape
    3.     For Each s In ActiveDocument.Shapes
    4.         PrintShapeText s
    5.     Next
    6. End Sub
    7.  
    8. Sub PrintShapeText(s As Shape)
    9.     Dim gs As Shape
    10.     If s.TextFrame.HasText Then
    11.         Debug.Print s.TextFrame.TextRange
    12.     Else
    13.         For Each gs In s.GroupItems
    14.             PrintShapeText gs
    15.         Next
    16.     End If
    17. End Sub
    This world is not my home. I'm just passing through.

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