Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Jul 2001
    Location
    Kuala Lumpur , MALAYSIA
    Posts
    154
    Thanks
    0
    Thanked 0 Times in 0 Posts

    is this possible ? (2000)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: is this possible ? (2000)

    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?

  3. #3
    2 Star Lounger
    Join Date
    Jul 2001
    Location
    Kuala Lumpur , MALAYSIA
    Posts
    154
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: is this possible ? (2000)

    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

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: is this possible ? (2000)

    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.

    <img src=/w3timages/blueline.gif width=33% height=2>

    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

    <img src=/w3timages/blueline.gif width=33% height=2>

  5. #5
    2 Star Lounger
    Join Date
    Jul 2001
    Location
    Kuala Lumpur , MALAYSIA
    Posts
    154
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: is this possible ? (2000)

    appreciate it very much hans

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

  6. #6
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Putnam Valley, New York, USA
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: is this possible ? (2000)

    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.

  7. #7
    2 Star Lounger
    Join Date
    Jul 2001
    Location
    Kuala Lumpur , MALAYSIA
    Posts
    154
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: is this possible ? (2000)

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

  8. #8
    2 Star Lounger
    Join Date
    Jul 2001
    Location
    Kuala Lumpur , MALAYSIA
    Posts
    154
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: is this possible ? (2000)

    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

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: is this possible ? (2000)

    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.

  10. #10
    2 Star Lounger
    Join Date
    Jul 2001
    Location
    Kuala Lumpur , MALAYSIA
    Posts
    154
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: is this possible ? (2000)

    thanks hans for the explanation.regards..

Posting Permissions

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