Sign in to follow this  
Followers 0
lordicast

_WordDocFindReplace

7 posts in this topic

This is strange the _WordDocFindReplace works fine when replacing in a text style document but will not replace text in a table like word document. Any thoughts?


[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites



What is a "table like word document"? Is that just any document with a table in it? Any chance you can provide a repro script/word doc?

Share this post


Link to post
Share on other sites

What is a "table like word document"? Is that just any document with a table in it? Any chance you can provide a repro script/word doc?

I had a thread a few weeks ago about this. It won't work in a text box, but it does in a table.

Regards,

William

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

So you can read out all cells of table:

#include <Word.au3>
Local $oWordApp = _WordCreate("Your.doc")
Local $rows, $columns

$rows = $oWordApp.Activedocument.Tables(1).Rows.Count       ; if not first table, use other number for table
$columns = $oWordApp.Activedocument.Tables(1).Columns.Count

$i = 1 ; row
$j = 1 ; col
For $i = 1 To $rows
    For $j = 1 To $columns
        $oWordApp.Activedocument.Tables(1).Cell($i,$j).Select
        ConsoleWrite($oWordApp.Selection.Text & @CRLF)
        ; If $oWordApp.Selection.Text = $SearchValue Then $oWordApp.Selection.Text = $Replacement
    Next
WEnd
Edited by BugFix

Best Regards BugFix  

Share this post


Link to post
Share on other sites

Thanks for replies, yes it is a textbox and it driving me mad!


[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Over a hundred files need 1 word changed! heres what i got

#include <Word.au3>
HotKeySet('{esc}', 'esc')

Func esc()
    Exit 0
EndFunc   ;==>esc
While 1
    _Move()
WEnd

Func _Move()
    Dim $MyExt[1] = ["doc"]

    For $i In $MyExt
        $search = FileFindFirstFile("*." & $i)
        While 1
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            TrayTip("Found File:", "Replace file " & $file, 10)

            $true = @ScriptDir & '\' & $file
            $oWordApp = _WordCreate($true, 0, 0)
            $oDoc = _WordDocGetCollection($oWordApp, 0)
            $oFind = _WordDocFindReplace($oDoc, "Orange", "Banana", 2, 0)

            _WordQuit($oWordApp, -1)

        WEnd
        FileClose($search)
    Next
    MsgBox(0, '', 'Done')
EndFunc   ;==>_Move

Error: --> Word.au3 Warning from function _WordDocFindReplace, $_WordStatus_NoMatch

Edited by lordicast

[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I've managed to figure it out after looking at various VBA macro examples on the web

For $j = 1 To $oDoc.Shapes.Count ;For all textboxes
                $oDoc.Shapes($j).Select ;Select Text box
                $oDoc.Application.Selection.WholeStory ;Select content
                $oFind = _WordDocFindReplace($oDoc, "yyyy", "xxxxxx",2,-1) ;Find in selected area
Next

HTH

Edited by RobertNaylor

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
Sign in to follow this  
Followers 0