How to Search for text in a word document and replace it

Hey All ,
I am able to open up a word document present locally using OLE2 Automation. Now i need to search for a text in that document
and replace it with another text. How do i achieve this?
And another issue is when i search for the particular pattern i need to store the pattern that comes after the pattern as i need it for further use before i replace it.
Thanks And Warm Regards,
Nischal

Hey Chen,
Well before i do the search and edit , I am actually opening a .mts file in word which is happening successfully.
The issue that i am facing now is I am unable to save it as .doc file through the 'SaveAs' method.
Here is my code. Can u please tell me what i need to do in order to correct this.
After i do this conversion i intend to pass the data from the .doc file to an internal table and then do the required change.
But First i need to save it to .doc type.
REPORT  MAIN_PROGRAM_2.
INCLUDE OLE2INCL.
*Declaration Of OLE2_Object Variables.
DATA: WORD            TYPE OLE2_OBJECT,
      DOCUMENTS       TYPE OLE2_OBJECT,
      ACT_DOCUMENTS   TYPE OLE2_OBJECT.
*Declaration of variables
PARAMETERS PATH       TYPE string.
DATA:Relative_Path    TYPE string,
     Relative_Path_Save    TYPE string.
*Declaration of an internal table
CONCATENATE PATH '\Script.mts' INTO RELATIVE_PATH.
*Object Creation in order for us to open word
CREATE OBJECT WORD 'WORD.APPLICATION'.
PERFORM ERROR_HANDLE.
*Set visibility property of MS word.
SET property of WORD 'VISIBLE' = 1.
*Open A document
CALL METHOD OF WORD 'Documents' = DOCUMENTS.
PERFORM ERROR_HANDLE.
*CALL METHOD OF DOCUMENTS 'ADD' = ACT_DOCUMENTS.
CALL METHOD OF DOCUMENTS 'OPEN' EXPORTING #1 = RELATIVE_PATH.
PERFORM ERROR_HANDLE.
*GET PROPERTY OF WORD 'ActiveDocument' = ACT_DOCUMENTS.
*PERFORM ERROR_HANDLE.
**To save the script.mts to script .doc file in order to put it into an internal table
CONCATENATE PATH '\Script.doc' INTO RELATIVE_PATH_SAVE.
CALL METHOD OF WORD 'SaveAs' EXPORTING #1 = RELATIVE_PATH_SAVE.
PERFORM ERROR_HANDLE.
FREE OBJECT WORD.
The Save part of the code is giving me an OLE error = 2
Thanks And Kind Regards,
Nischal
Edited by: Nischal HP on Apr 28, 2011 1:53 PM

Similar Messages

  • How do I select texte discontinuouly : one word here and another there

    How do I select texte discontinuouly : one word here and another there, etc.

    Use Pages '09.
    Feature has been removed from Pages 5, along with 100+ others.
    Peter

  • Help! I've deleted most text in a Word document and pressed save!

    Help! I've deleted most text in a Word document accidentally and pressed save - thus losing most of the last week's work! Is there likely to be a temp file anywhere from yesterday so that I can retrieve it?

    I don't know which Mac you have, but if you have an intel, update to 10.7 and you can use the function called Versions, which autmatically saves a version of your text, and you can revert to it when needed.

  • Search for a string in word document using VBA

    Hi,
    I am new to VBA. My requirement is that VBA code should find the path in the word document., some of the paths are present in the word document.
    search criteria should start with \\\\ and end with .doc. Could anyone please help me out on how to provide the search criteria and is there any predefined methods present.
    Thanks in advance.
    Thanks,.

    Apologies, the line
    Do While .Execute(FindText:=.Text = "\\\\*.doc", MatchWildCards:=True)
    should read
    Do While .Execute(FindText:="\\\\*.doc", MatchWildCards:=True)
    It will however only work for the document body. If the string is in a different story range you will have to loop through those story ranges e.g.
    Sub FindIt()
    Dim wdApp As Object
    Dim wdDoc As Object
    Dim oRng As Object
    Dim bStarted As Boolean
    Dim i As Integer
        On Error Resume Next
        Set wdApp = GetObject(, "Word.Application")
        If Err Then
            Set wdApp = CreateObject("Word.Application")
            bStarted = True
        End If
        On Error GoTo 0
        ActiveWorkbook.Save
        Set wdDoc = wdApp.Documents.Open("C:\Path\DocumentName.docx")
        i = 1
        For Each oRng In wdDoc.StoryRanges
            With oRng.Find
                .MatchWildcards = True
                Do While .Execute(FindText:="\\\\*.doc")
                    Range("A" & i) = oRng.Text
                    oRng.Collapse 0
                    i = i + 1
                Loop
            End With
            If oRng.StoryType <> wdMainTextStory Then
                While Not (oRng.NextStoryRange Is Nothing)
                    Set oRng = oRng.NextStoryRange
                    With oRng.Find
                        .MatchWildcards = True
                        Do While .Execute(FindText:="\\\\*.doc")
                            Range("A" & i) = oRng.Text
                            oRng.Collapse 0
                            i = i + 1
                        Loop
                    End With
                Wend
            End If
        Next oRng
        wdDoc.Close 0
        If bStarted Then wdApp.Quit
        Set oRng = Nothing
        Set wdDoc = Nothing
        Set wdApp = Nothing
    End Sub
    Graham Mayor - Word MVP
    www.gmayor.com

  • How to search for text in document

    How do you search text within a document on the Samsung Galaxy 10.1? I click the search icon, enter the text to search and nothing happens. The only options I see are a circled "x" and "Cancel". The program does not automatically go to the entered search string and I cannot find anyway to cause the program to find the words. Thanks,

    Once you have typed your search term in, you need to tap the "enter" key on the keyboard. Once you do, the keyboard should close, and you should see the first instance selected.
    There will be two Arrow buttons in the bottom center of the screen to go back and forth through all of the instances of this word in the document.
    If the word could not be found, then a message displaying "search term" not found will appear at the bottom of the screen above those buttons.

  • How to search for text inside multiple pdf file at once in ipad

    Hi
    I am student and i need search a word or subject or sentences on my all pdf files,i have tested some applications like ibook, ipdf, addobe reader, good reader ,....  But couldn't find what i need to have.
    Please kindly help me to find the best application.
    Thanks

    I found an article, that claims PDF Expert does exactly what you are asking.
    Article: http://www.imore.com/pdf-expert-ipad-brings-full-text-search-pdf-library
    PDF Expert: https://itunes.apple.com/us/app/pdf-expert-fill-forms-annotate/id393316844?mt=8

  • How do I transfer text messages to word document in computer

    I want to transfer text messages from my Iphone 6 to my Mac Pro.   How do I do this?

    And thanks for replying so fast.   Now I can get my transfer done today

  • How to duplex print from a MS Word document in HP 1020 Plus printer

    Two days before I have acquired a HP 1020 Plus Laserjet printer . How to duplex print from a MS Word document and Corel Draw document in HP 1020 Plus printer? I tried manual duplex printing by printing the odd pages first and then even pages ....it came out correct ,...but whenit comes to Page numbers continuity it is not properly printed ....why?? Can anyone highlight on this and give me a step by step instructuion to print Duplex and thereby help me to create 20-----------page or 30 page booklets.....from MS word typed document or corel draw document......Expecting a speedy solution
    thanks & regards,
    K Narayanan
    This question was solved.
    View Solution.

    @immo22269  
    The laserjet 1020 only has manual duplexing capabilities. Please refer to this document for a complete set of instructions.
     Print on both sides of the paper (manual duplexing)
    I am an HP employee.
    Say Thanks by clicking the Kudos Star in the post that helped you.
    Please mark the post that solves your problem as Accepted Solution

  • How to search for words in binaries (jpg,bmp,tif,...) ??

    Hello,
    is it possible to index words from images with tenable effort ?
    We are developing a document-management-system and it would be nice
    when search includes images.
    I would appreciate very much any suggestions, links or solutions.
    regards,
    Tim

    >
    Do you mean words in images in the sense of an image
    comment (which is not visible when the image is
    displayed, but some image editors can detect and
    expose as an image property), or as text displayed as
    part of the image, like this:
    http://developer.java.sun.com/images/v4_java_sun_com.gi
    If the latter, forget it.Hello,
    first thanks for answers, I was looking for a possibility to search for text in images in order to save it in a database.
    So its the latter :(
    I thought it could be possible to use any scanner-drivers for this purpose:
    http://www.openarchive.com/echive_tifindexer.htm
    But I'm not sure how to achieve this.
    regards,
    Tim

  • How to search for a particular word in a string?

    How to search for a particular word in a string?
    thanks for your help....

    This works fine.
    public class Foo {
        public static void main(String[] args) {
        String s = "Now is the time for all good...";
        String s2 = "the time";
        System.out.println(s.contains(s2));
        System.out.println(s.contains("for al"));
        System.out.println(s.contains("not here"));
    }output:true
    true
    falseYou must have something else wrong in your code.
    JJ

  • How to search for a particular word in a long document?

    How to search for a particular word in a long document?

    What program are you using to read the document?
    Good luck.

  • How to search for a word in an email?

    How to search for a particular word in an email in 'Mail'?

    You can't search through email content using buil-in search
    If you're using Gmail, you can use their native Google Mail app which will allow you to search through body content and server-stored emails.

  • How do I search for text on a webpage?

    I have found some answers for mobile devices, but how do I search for text on a webpage for my notebook?

    You will find command F is fairly universal.
    good computing

  • How to search for a certain cross reference using its name in FM 11?

    How to search for a certain cross reference using its name in FM 11?

    Well, thank you. I am only using Find dialog box. By "name", I'd like to give an example. The background is FM 11 structured. I have an element "xref" which is used to make cross reference. Now In Chapter 1, there is a sentence like "This is an ODU for ...". I made a cross ref of the word "ODU" to its full name "outdoor unit" in Chapter 2 (in the same book). After this, the word "ODU" in the sentence in Chapter 1 will no longer be a plain text. So I no longer can use the find dialog box to search for "ODU" because it is already an xref rather than text. I am not if it's clear.

  • How to search for upper/lower case using string using JAVA!!!?

    -I am trying to write a program that will examine each letter in the string and count how many time the upper-case letter 'E' appears, and how many times the lower-case letter 'e' appears.
    -I also have to use a JOptionPane.showMessageDialog() to tell the user how many upper and lower case e's were in the string.
    -This will be repeated until the user types the word "Stop". 
    please help if you can
    what i have so far:
    [code]
    public class Project0 {
    public static void main(String[] args) {
      String[] uppercase = {'E'};
      String[] lowercase = {'e'};
      String isOrIsNot, inputWord;
      while (true) {
       // This line asks the user for input by popping out a single window
       // with text input
       inputWord = JOptionPane.showInputDialog(null, "Please enter a sentence");
       if ( inputWord.equals("stop") )
        System.exit(0);
       // if the inputWord is contained within uppercase or
       // lowercase return true
       if (wordIsThere(inputWord, lowercase))
        isOrIsNot = "Number of lower case e's: ";
       if (wordIsThere(inputword, uppercase))
         isOrIsNot = "number of upper case e's: ";
       // Output to a JOptionPane window whether the word is on the list or not
       JOptionPane.showMessageDialog(null, "The word " + inputWord + " " + isOrIsNot + " on the list.");
    } //main
    public static boolean wordIsThere(String findMe, String[] theList) {
      for (int i=0; i<theList.length; ++i) {
       if (findMe.equals(theList[i])) return true;
      return false;
    } // wordIsThere
    } // class Lab4Program1
    [/code]

    So what is your question? Do you get any errors? If so, post them. What doesn't work?
    And crossposted: how to search for upper/lower case using string using JAVA!!!?

Maybe you are looking for

  • Deactivating Elements on an old hard disk

    I had Elements 8 installed both on my Desktop and Laptop computers, but then bought Elements 9 and installed that on the Desktop - but didn't know about deactivating Elements 8 until I bought a third (Netbook) computer and wanted to install Elements

  • BB 10 OS update, Can't install it whatever I do...

    I get a notification every few days in my BB hub saying there's a software update to install: Blackberry 10 OS update, version 10.2.1.2977. It's been happening for months now, but whatever I do I can't install it! When I start trying to install it, i

  • ı have iphone 4 and upgrade os 6.0.1 and excell problem.

    ı have iphone 4 and upgrade os 6.0.1 and at now when open from mails excell files ı can't see date cells are ın side the cell diferrrent characters like format type. ı send one screenshot from my phone.

  • SAP query in SQ02

    Good afternoon, I made a query, and this is to return everything I need, but doubling this lines, each row is always displayed twice. It is possible in SQ02 put some sort of code to be displayed only one line? Best regards, António Pinho

  • Power Button is "stuck" or sticky

    How can I get it to operate normally again? I have to push down really hard just to make it work again, I have a gen 2, 32 gig