Jump to content

Find wrapped images in Word document

Go to solution Solved by Nine,

Recommended Posts

I have a .docx that has some wrapped images in it.

If I use "^g" into search, it does not find them (I think because they are not inline pictures). If I use the Go-To with Graphic, it correctly detects them.

How can I find them with Word UDF?

I attach a docx example: I want to detect that recipe 2 has not a picture near the title.

I used this to detect the titles with style Header 3 :


#include <Array.au3>
#include <String.au3>
#include <Word.au3>

global $oDoc = _Word_DocOpen($oWord, "filename.docx")

global $oRangeFound = _Word_DocFind($oDoc," ", Default, Default) 

While 1
    $oRangeFound = _Word_DocFindEX($oDoc, Default, Default, $oRangeFound, Default, Default, Default, Default, Default, Default, "Heading 3")



Link to comment
Share on other sites

Thank you for the workaround.
But it's not that easy to detect which picture belongs to which title... they are named generically "ImageXX.png" without reference to the title.

I don't need to extract the QR png, I need to find out which title hasn't a picture (to add a QR with a script)
Of course I have a lot of them, the file attached is a tiny example...

Link to comment
Share on other sites

Thank you Nine.

That's an improvement!

I got every QR and I can see which title there is on the paragraph near to the shape with:

local $par = $oShape.Anchor.Paragraphs(1).Range.Text

This way I could make an array with all the titles with QR. Then I should make another loop, searching all titles and searching in the previous array to see if there is a QR.


But I would like to get the inverse., much linear..:

Having a range with the title, I would like to get the shape near it, if any...

How to get a shape in a range instead of all shapes in doc?



Link to comment
Share on other sites

  • Solution
Posted (edited)

I suppose you could get the title range, then use ShapeRange(1) to get QR within that range (untested).  You will need to intercept the COM error if there is no QR within that range.

If that does not work, post the code you got (based on the docx you provided), so we don't have to start from scratch...

ps. I finally was curious about it, so here the code I used :

#include <Word.au3>

Local $oError = ObjEvent("AutoIt.Error", Error)
Local $oWord = _Word_Create()
Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\testQR.docx")

For $oPar In $oDoc.paragraphs
  With $oPar
    If .style.NameLocal = "Titre 3" Then   ; <<<<<<<<<< change to your language
      If @error Then ConsoleWrite(StringStripWS(.range.text, 3) & " does not have a QR" & @CRLF)

Func Error($oError)
EndFunc   ;==>ErrFunc


Edited by Nine
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

  • Recently Browsing   0 members

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