Jump to content

_WordDocFindReplace


Recommended Posts

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

Link to comment
Share on other sites

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  

Link to comment
Share on other sites

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]
Link to comment
Share on other sites

  • 9 months later...

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...