viptnn

Need to help replace multipe word in MS Word

12 posts in this topic

I have a document of 100 pages. i need to replace a lot of characters and words 
For example  ∂,∆, π, lee ≈  with 'de', 'trang', 'P', 'loo' accordingly. 

_Word_DocFindReplace($oDoc, "∂", "de") can do ok, but replace single word and take too long time.
How i can i search multiple letters(or even words) and replace it?

Please help.

I found VBA code maybe do work, if could pls translate to autoit thanks.

Sub MultiReplace()
Dim StrFind As String, StrRepl As String
Dim i As Long
StrFind = "∂,∆,π,lee "
StrRepl = "de,trang,P,loo"
Set RngTxt = Selection.Range
For i = 0 To UBound(Split(StrFind, ","))
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = Split(StrFind, ",")(i)
.Replacement.Text = Split(StrRepl, ",")(i)
.Format = False
.MatchWholeWord = True
.MatchAllWordForms = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
Next i
End Sub

 

Share this post


Link to post
Share on other sites



6 hours ago, viptnn said:

I found VBA code maybe do work, if could pls translate to autoit thanks.

What did you try as the code should look pretty similar, or did you want to pay me for doing it for you?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Did you have a look at the Word UDF that comes with AutoIt?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
1 hour ago, Jos said:

What did you try as the code should look pretty similar, or did you want to pay me for doing it for you?

Jos

i could to pay you if you have time to help me complete my program.

Share this post


Link to post
Share on other sites
Just now, viptnn said:

i could to pay you if you have time to help me complete my program.

Doubt that ;)

So you better take the cheap option and give the suggestions a try yourself.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
1 hour ago, water said:

Did you have a look at the Word UDF that comes with AutoIt?

i looked but no func can replace multi word at same time, i have a lot of word need to replace so i want replace all as fast as well

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

8 minutes ago, Jos said:

Doubt that ;)

So you better take the cheap option and give the suggestions a try yourself.

Jos

Thank Jos, pls show the suggestions, i ll try myself :)

Edited by viptnn

Share this post


Link to post
Share on other sites

With multiple words to replace I would call _Word_DocFindReplace in a loop.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
3 minutes ago, water said:

With multiple words to replace I would call _Word_DocFindReplace in a loop.

i known that way but i need to give an example for you to understand

_Word_DocFindReplace($oDoc,"word1","one")

It take 0.5 second, very fast alright? but if we loop to 100-1000 time, it take 50-500 second too long if we compare with vba script

Share this post


Link to post
Share on other sites

Did you try to translate the VBA code to AutoIt?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
1 minute ago, water said:

Did you try to translate the VBA code to AutoIt?

No, i didn't i study only Autoit code :(, if you could pls help me, i dont want my program slower than VBA code

Share this post


Link to post
Share on other sites

Something for you to start with:

#include <Word.au3>
Global $oWord ; Set Word application object here and assign object
Global $oDoc ; Open Word document here and assign object 
Func MultiReplace()
    Local $aFind = StringSplit("∂,∆,π,lee", ",")
    Local $aReplace = StringSplit("de,trang,P,loo", ",")
    Local $oRange = $oWord.Selection.Range
    For $i = 1 To $aFind[0]
        $oWord.Selection.HomeKey($wdStory)
        With $oWord.Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = $aFind[$i]
            .Replacement.Text = $aReplace[$i]
            .Format = False
            .MatchWholeWord = True
            .MatchAllWordForms = False
            .Replace($wdReplaceAll)
            .MatchWildcards = False
            .Execute()
        EndWith
    Next
EndFunc   ;==>MultiReplace

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now