Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I'm trying to work with a Word document via Access Automation. I want to search for and replace certain character strings since there are no bookmarks, tables, formfields, or other markers in the text and I can't alter the original document. I just can't seem to figure out how to do it.
    The range method looks promising but I can't get it to work.
    I tried this: doc.Paragraph(5).Range.Characters = "New Text" but that didn't work,
    So I tried declaring: "Dim rngText As Range" and then setting rngText this way: Set rngText = doc.Paragraph(5).Range but that didn't work either.
    What am I missing?
    What I really need to do is search for text and replace it in the document. Is there a better way to do this?
    Thanks for any info you can give me or any place you can send me for info!

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    [quote name='VBA-Bumbler' post='774222' date='08-May-2009 10:29']I'm trying to work with a Word document via Access Automation. I want to search for and replace certain character strings since there are no bookmarks, tables, formfields, or other markers in the text and I can't alter the original document. I just can't seem to figure out how to do it.
    The range method looks promising but I can't get it to work.
    I tried this: doc.Paragraph(5).Range.Characters = "New Text" but that didn't work,
    So I tried declaring: "Dim rngText As Range" and then setting rngText this way: Set rngText = doc.Paragraph(5).Range but that didn't work either.
    What am I missing?
    What I really need to do is search for text and replace it in the document. Is there a better way to do this?
    Thanks for any info you can give me or any place you can send me for info![/quote]


    I have just tried this and it works OK for searching the whole document.
    Code:
    Dim rng As Word.range
     Set rng = wrd.ActiveDocument.Content
     With rng.Find
    	 .Text = strSearchText
    	 .Forward = True
    	 .Replacement.Text = strReplacetext
    	 .Execute Replace:=wdReplaceAll
    End With
    Regards
    John



  3. #3
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    John,
    That works perfectly! Thank you very, very much!!!
    Thanks

Posting Permissions

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