Results 1 to 5 of 5

Thread: Retrieving text from MS Word document

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Location
    Mostar, Bosnia and Hercegovina
    Posts
    16

    Retrieving text from MS Word document

    I need to retrieve all text from MS Word document where word style is Heading 1, and show that on text box. Anyone know how to recognize what word style is used on some place in Word Document?

    I know how to open document, or find a text, but how to find which word style is used. I try something like:
    If objWord.ActiveDocument.Paragraph.Item(i).Style = "Normal" Then ....

    but doesnt work.

    I get error:
    Additional information: Operator is not valid for type 'Style' and string "Normal".

    That code works fine in Visual Basic 6

  2. #2
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    Haven't tried this myself, but I think its a fair guess.....

    Code:
    If Selection.Style = ActiveDocument.Styles("Normal") Then

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Location
    Mostar, Bosnia and Hercegovina
    Posts
    16
    There is no error
    Thanks a lot Athley.

    With:
    objWord.Selection.Find.Style = "Heading 1"
    x = Selection.text

    Give me only the first character of paragraph. Is it possible to select whole paragraph when I find style?

  4. #4
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    Again I haven't tried it....

    Code:
    Selection.Expand (wdParagraph)
    You probably have to retrieve the Selection.Text after that as well...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Location
    Mostar, Bosnia and Hercegovina
    Posts
    16
    I find it!!!

    Thanks again Athley

    There is vb.net code if someone need the same thing:
    PHP Code:
    objWord.Selection.Find.Style "Normal"
    objWord.Selection.Find.Execute(FindText:=""Format:=True_
            Forward
    :=TrueWrap:=Word.WdFindWrap.wdFindStop)
    MsgBox(objWord.Selection.Text

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