Lipko Posted June 30, 2020 Report Share Posted June 30, 2020 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! Quote Link to comment
Lipko Posted July 9, 2020 Author Report Share Posted July 9, 2020 (edited) 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 July 9, 2020 by Lipko 1 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.