Jump to content

Report Generation - Insert Image at Text (find text then replace with image)

Recommended Posts

Hi all,

I'm trying to insert images at specific texts in a Word document with the Report Generation Toolkit. Kind of like search and replace, but with an image as replacement.
All I found that inserting a picture can be either done at bookmarks or into table cells.
I want to avoid Bookmarks because it's easier to add some hashtags than editing bookmarks if there are dozens of images to be inserted.
I didn't find any way to either set the cursor or add bookmarks programmatically. Actually, I don't find any usage of the cursor in the built-in RGT functions…

I thought it's a basic thing I want to solve but didn't find appropriate answers.

Thanks for any hints in advance!

Link to comment
  • 2 weeks later...

It can be solved with a fairly simple macro.

Sub ReplaceTextWithImage(findText as string,  imagePath As String)
    If Selection.Find.Execute(FindText:=findText, MatchWholeWord:=True, Forward:=True, Wrap:=wdFindContinue) = True Then
        Selection.InlineShapes.AddPicture FileName:=imagePath, LinkToFile:=False, SaveWithDocument:=True
    End If
End Sub


EDIT: added checking if text found and MatchWholeWord and continue search if out of selection range.
Other checks should be added to the labview code (image file exists and findText not empty).

Note, that the Selection.Find.Execute will ignore MatchWholeWord if there are special characters in the findText for some reason. I haven't found a reference to what charaters are "special". Special characters I tried and found: &, #, _ So I gueass pretty much every non alphabetical....

Edited by Lipko
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.