Jump to content
Sign in to follow this  
Jury

Word find/replace graphics

Recommended Posts

Jury

Why doesn't this work?  If I use ^g in a macro it works and when I use ^p (to replace a paragraph) it works?

#include <Word.au3>
#include <MsgBoxConstants.au3>

Global $oWord = _Word_Create(False)

$processing = @MyDocumentsDir & '\AutoIt_code\getter\processing\'

$oDoc = _Word_DocOpen($oWord, $processing & "1200.doc", Default, Default, False)
_Word_DocFindReplace($oDoc, "^g", "image removed", $WdReplaceAll)
If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
        "Error replacing text in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", "Paragraph control character successfully replaced.")
_Word_DocClose($oDoc, $WdSaveChanges)
_Word_Quit($oDoc)

Share this post


Link to post
Share on other sites
water

Try to set parameter $bMatchWildcards = True

Based on this page.

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
water

Then we need more information:

Which AutoIt version?

Which Office version?


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
Jury

Sorry water - I've just deleted my reply because I created a fresh doc file with an image in it and it worked - just as you said it would.  It seems the files that I'm working on have something different about the images which causes the problem.  Once again thanks for your valuable help.  So in the end this works for removing all normal images from a file:

$oDoc = _Word_DocOpen($oWord, "filepath/filename.doc", Default, Default, False)
_Word_DocFindReplace($oDoc, "^g", "", $WdReplaceAll, 0, False, False, False)
_Word_DocClose($oDoc, $WdSaveChanges)
_Word_Quit($oDoc)
Edited by Jury

Share this post


Link to post
Share on other sites
water

:)

  • Like 1

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.