LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Word Report Gen Toolkit - Find String Location

Solved!
Go to solution

Hey guys,

 

Does anybody know how to search a Word document for a string and output the location at which the string was found?

The closest I can find is NI_Word.lvclass:Word Find & Replace (str).vi, which looks like this:

Word Find and Replace.png

But it does the replacement using the Find command and doesn't output any range for the find.

 

To elaborate on my end goal:

I'm trying to append an array of pages to my report. The pages are identical except for the specific values within the page, so I'm loading them as a second Word document template and inserting that doc in to the main template. There are two images on each page, but the only way to insert an image in to the Word report is using a Bookmark or a Range. Unfortunately, you can't have duplicate bookmarks, so only one of the generated pages has the bookmarks if I try to use them. This is where I run in to problems and am hoping to use a known string on each page (from the template) to locate the spot where I need to insert the images.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 1 of 4
(3,275 Views)
Solution
Accepted by topic author James.M

That looks like VBA to me.  If so, you can try making your own function, modified as follows:

  • (Quoting Microsoft):  To specify a graphic object or other nontext item as the replacement, move the item to the Clipboard and specify "^c" for ReplaceWith.
  • The "Replace" entry says how many replacements to make, including 0 (don't replace).

Hope this helps.

 

Bob Schor

Message 2 of 4
(3,255 Views)

Thanks for the help, Bob. It looks like my home computer's Word install doesn't like LabVIEW, so I'll have to test the ^c method tomorrow. That might solve my problems as long as I can copy the images easy enough.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 3 of 4
(3,246 Views)
Solution
Accepted by topic author James.M

That worked out great! It took some extra work to make the pasted image in-line (just like the text originally was). I haven't done much with the Report Gen Toolkit in the past, but I'm learning now that it's quite limited. Using the VBA methods to program Word myself gives a ton of flexibility and I like it a lot.

 

For others visiting this thread, here's what I've done:

Report-Word_FileIO.lvclass_(Delete Me) Testing Insert Defects_BD.png

 

I used this community post to copy the image to clipboard, the "^c" replace string to paste it, and this code to set text wrapping to InLine (also in the subVI included).

 

Thanks for the help, Bob!

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 4 of 4
(3,210 Views)