KickStarter15

[Solved] Function _Word_DocFindReplace() can be changed?

10 posts in this topic

#1 ·  Posted (edited)

Hi Experts,

I just want to ask and assistance if _Word_DocFindReplace() can be changed of what you want to replaced and not all characters in "$oFind" will be replaced? Like, I want to find "^$^#^p" in the document and replace only "^p" with delimiter "; ".

#include <Word.au3>
Local $oWord = _Word_Create()
Local $sDocument = @ScriptDir & "\word.docx"
Local $oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, True)
$oFind = "^$^#^p" ; I want only "^p" to be replaced
$oReplace = "; "
_Word_DocFindReplace($oDoc, $oFind, $oReplace, $wdReplaceOne, 0, True, True)

Thanks in advance Experts,

KS15

Edited by KickStarter15

Share this post


Link to post
Share on other sites



#2 ·  Posted

Why not use

$oFind    = "^$^#^p" ; I want only "^p" to be replaced
$oReplace = "^$^#; "

 


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 ·  Posted

@water Thanks, I tried that one but the code will not execute, "^$" and "^#" is not recognized as characters in "$oReplace" but if you change "^$" to "a" and "^#" to "1" then the code will execute replacing "$oFind".

Share this post


Link to post
Share on other sites

#4 ·  Posted

I think the following document is a good reading how to solve your problem:
http://wordmvp.com/FAQs/General/UsingWildcards.htm


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

#5 ·  Posted

@water, Thank you for this reading guide on how to handle find and replace in document using wildcards. This is a big help for me in my future projects.^_^ However, after reading the guide, it seems that it is all about replacing the characters to find using wildcards and not replacing the characters being found or was found in _Word_DocFindReplace().

In "$oFind", lets say we use the wildcards from guide, It is still the same concern with this:

On 4/14/2017 at 3:41 PM, KickStarter15 said:

"^$" and "^#" is not recognized as characters in "$oReplace" but if you change "^$" to "a" and "^#" to "1" then the code will execute replacing "$oFind".

The wildcard being searched is not valid when replacing "$oFind" with "$oReplace". Or maybe, I'm just being so mashup with my understanding with the guide.:sweating:

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

Does it make a difference if you set parameter $bMatchWildcards to True? Default si False.


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

#7 ·  Posted (edited)

Oops! missed that one.:)

Here it is, I tried having it declared as below but still having the same issue.

Find for numbers "[0-9]" followed by paragraph marks "^13" and replace with "[0-9]; " and the output is "word[0-9]; " from "word1^13".:(

$oFind = "[0-9]^13"
$oReplace = "[0-9]; "
With $oWord.Selection.Find
   .ClearFormatting
   .Replacement.ClearFormatting
;~    expression.Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards, &_
;~ MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace,&_
;~ MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl)
   .Execute($oFind, false, false, true, false, false, true, false, false, $oReplace, $wdReplaceAll)
EndWith
MsgBox(0,"","Done!")

I think this is impossible to do right @water?:'( I just need to replace paragraph marks after the number with delimiter "; " but why so hard.

Tried it also this way, the same issue.

$oFind = "[0-9]^13"
$oReplace = "[0-9]; "
; _Word_DocFindReplace($oDoc, FindText, ReplaceText, $iReplace, $vSearchRange, $bMatchCase, $bMatchWholeWord, $bMatchWildcards)
_Word_DocFindReplace($oDoc, $oFind, $oReplace, $wdReplaceOne, False, False, False, True)

 

Edited by KickStarter15

Share this post


Link to post
Share on other sites

#8 ·  Posted

Can't test at the moment but I think it could be something like this:

$oFind = "([0-9])^13"
$oReplace = "\1; "

 

1 person likes this

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

#9 ·  Posted

@water I admit that I really need to understand the guide you shared to me. Thanks a lot, that simple code do the trick. :D

Thank you so much Water. Now I should read and understand this guide.:lol:

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Glad this little piece of code works for you.
I will add have added the link to the wiki for future reference.

Edited by water

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