• is this possible ? (2000)

    Author
    Topic
    #408908

    Hello,

    i’m a newbie in words..but i have 2 difificult question to ask the pro’s here

    lets say i have 5 words documents..let say..

    a.doc
    b.doc
    c.doc
    d.doc
    e.doc

    above is the documents name

    what i want to do..let say..i open the “a.doc” and edit all the the other 4 documents without opening it

    the task are :

    1. find all “abc” in other 4 docs and replaced it with “xyz”

    2. delete all “def” in all of the 4 docs..

    please remember that i want to do this without open the other 4 docs.

    so i need some sort of macros aka vba to do this..

    is it possible..thanks

    Viewing 3 reply threads
    Author
    Replies
    • #867357

      It is impossible to edit a Word document without opening it. You can use VBA code to replace text in the documents, but the code will have to open each document, edit it, then close it again. Why do you object to the documents being opened?

      • #867363

        thanks hans ,

        i dont want to opened the files because ..its too many..the example i give in this post is not the exact total of my files..

        let say if i have 100 files..so it takes a long time for me to edit it..then closed it..open another one..then close it..and so on..

        so i need so automate it to make my work more efficient..thats why i need that macro..

        could you please help me hans..thanks

        • #867369

          If you have a lot of documents to process, move them all into one folder. This folder should only contain documents to be processed, no other documents.

          Start Word.
          Activate the Visual Basic Editor (Alt+F11)
          Insert a new module (Insert | Module)
          Copy the code at the end of this reply, and paste it into the module.
          Change the path “C:Word” to the path of the folder containing the documents.
          This path should include a trailing backslash.
          Change the text “abc” etcetera to the actual text you want to find / replace.
          Click somewhere in the code, and press F5 to run it.
          You can also run the macro from Word itself:
          – Select Tools | Macro | Macros…
          – Select ProcessFiles in the list of macros.
          – Click Run.

          Sub ProcessFiles()
          ‘ Edit as needed, but keep trailing backslash
          Const strPath = “C:Word”
          Dim strFile As String
          Dim doc As Document

          On Error GoTo ErrHandler

          strFile = Dir(strPath & “*.doc”)
          Do While Not strFile = “”
          Set doc = Documents.Open(FileName:=strPath & strFile, AddToRecentFiles:=False)
          With doc.Content.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          ‘ Change the text as needed
          .Execute FindText:=”abc”, ReplaceWith:=”xyz”, Replace:=wdReplaceAll
          .Execute FindText:=”def”, ReplaceWith:=””, Replace:=wdReplaceAll
          End With
          doc.Close SaveChanges:=wdSaveChanges
          strFile = Dir
          Loop

          ExitHandler:
          Set doc = Nothing
          Exit Sub

          ErrHandler:
          MsgBox Err.Description, vbExclamation
          Resume ExitHandler
          End Sub

          • #867385

            appreciate it very much hans

            i will try the code and will tell you the result..regards

          • #867386

            appreciate it very much hans

            i will try the code and will tell you the result..regards

          • #867467

            hellp hans,

            so far your code works perfectly..

            just 1 simple question..but its so hard for me that dont so familiar with words..

            let saya i want to use button..like command button..

            in other word, i want to use your code..and attach it to a button..

            so when ever i push the button..your code will run..

            i try to use the command button..but unfortunately , it fail..

            havy any idea..thanks

            • #867477

              If you want a command button in a document:
              – Display the Control Toolbox toolbar.
              – Click on the Command Button on the toolbar, then click in the document.
              – This will place a command button in the document, and turn on design mode.
              – Right click the command button in the document and select View Code from the popup menu.
              – Make the code look like this:

              Private Sub CommandButton1_Click()
              ProcessFiles
              End Sub

              where CommandButton1 is the name automatically assigned to the button, and ProcessFiles is the name of the procedure you copied from my earlier reply.
              – Switch back to Word.
              – Turn off Design mode using the button on the Control Toolbox or on the small Exit Design Mode toolbar.

            • #867507

              thanks hans for the explanation.regards..

            • #867508

              thanks hans for the explanation.regards..

            • #867478

              If you want a command button in a document:
              – Display the Control Toolbox toolbar.
              – Click on the Command Button on the toolbar, then click in the document.
              – This will place a command button in the document, and turn on design mode.
              – Right click the command button in the document and select View Code from the popup menu.
              – Make the code look like this:

              Private Sub CommandButton1_Click()
              ProcessFiles
              End Sub

              where CommandButton1 is the name automatically assigned to the button, and ProcessFiles is the name of the procedure you copied from my earlier reply.
              – Switch back to Word.
              – Turn off Design mode using the button on the Control Toolbox or on the small Exit Design Mode toolbar.

          • #867468

            hellp hans,

            so far your code works perfectly..

            just 1 simple question..but its so hard for me that dont so familiar with words..

            let saya i want to use button..like command button..

            in other word, i want to use your code..and attach it to a button..

            so when ever i push the button..your code will run..

            i try to use the command button..but unfortunately , it fail..

            havy any idea..thanks

        • #867370

          If you have a lot of documents to process, move them all into one folder. This folder should only contain documents to be processed, no other documents.

          Start Word.
          Activate the Visual Basic Editor (Alt+F11)
          Insert a new module (Insert | Module)
          Copy the code at the end of this reply, and paste it into the module.
          Change the path “C:Word” to the path of the folder containing the documents.
          This path should include a trailing backslash.
          Change the text “abc” etcetera to the actual text you want to find / replace.
          Click somewhere in the code, and press F5 to run it.
          You can also run the macro from Word itself:
          – Select Tools | Macro | Macros…
          – Select ProcessFiles in the list of macros.
          – Click Run.

          Sub ProcessFiles()
          ‘ Edit as needed, but keep trailing backslash
          Const strPath = “C:Word”
          Dim strFile As String
          Dim doc As Document

          On Error GoTo ErrHandler

          strFile = Dir(strPath & “*.doc”)
          Do While Not strFile = “”
          Set doc = Documents.Open(FileName:=strPath & strFile, AddToRecentFiles:=False)
          With doc.Content.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          ‘ Change the text as needed
          .Execute FindText:=”abc”, ReplaceWith:=”xyz”, Replace:=wdReplaceAll
          .Execute FindText:=”def”, ReplaceWith:=””, Replace:=wdReplaceAll
          End With
          doc.Close SaveChanges:=wdSaveChanges
          strFile = Dir
          Loop

          ExitHandler:
          Set doc = Nothing
          Exit Sub

          ErrHandler:
          MsgBox Err.Description, vbExclamation
          Resume ExitHandler
          End Sub

      • #867364

        thanks hans ,

        i dont want to opened the files because ..its too many..the example i give in this post is not the exact total of my files..

        let say if i have 100 files..so it takes a long time for me to edit it..then closed it..open another one..then close it..and so on..

        so i need so automate it to make my work more efficient..thats why i need that macro..

        could you please help me hans..thanks

    • #867358

      It is impossible to edit a Word document without opening it. You can use VBA code to replace text in the documents, but the code will have to open each document, edit it, then close it again. Why do you object to the documents being opened?

    • #867421

      I don’t use this product, but you may want to look into a product called Mega-Replacer. It costs thirty dollars, but there is an evaluation period so you can try before you buy.

      • #867465

        thanks Eowyn..for the link and the info..
        will try it both..hehe

      • #867466

        thanks Eowyn..for the link and the info..
        will try it both..hehe

    • #867422

      I don’t use this product, but you may want to look into a product called Mega-Replacer. It costs thirty dollars, but there is an evaluation period so you can try before you buy.

    Viewing 3 reply threads
    Reply To: is this possible ? (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: