From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Report generation tool kit - Word Find and replace VI

I am using Word Find & Replace VI to replace some texts in the doc.  It works fine on the content area but seemed that it doesn't work in the footer and header area.  Is it the limitation of this VI or Have I missed something?

0 Kudos
Message 1 of 7
(3,186 Views)

It is a limitation of the toolkit.  You'll need to create some additional ActiveX calls to activate the header/footer and search in those locations as well. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 7
(3,146 Views)

I wouldn't call it a limitation of the toolkit. This is how Microsoft implemented the Find and Replace operation on the Document range and it make sense that the headers and footers are not automatically changed by the replace operation.

 

Ben64

0 Kudos
Message 3 of 7
(3,141 Views)

@ben64 wrote:

I wouldn't call it a limitation of the toolkit. 

I would and did.  When you search and replace in Word, it does search the entire document, including the headers/footers.  The toolkit does not.  This could have been included as an option in the subVI but NI chose not to do that.  I'm not blaming NI but it is what it is.  And now as a user that wants to search headers and footers, additional functionality will need to be implemented. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 4 of 7
(3,138 Views)

I don't know what's under the hood when a find and replace operation is performed in Word and I may be wrong but my feeling is that Word knows the document structure and can perform the replacements in the sections and containers that Word knows are there. When using ActiveX we don't have this knowledge so an algorithm would have to check if there are headers and footers, how many different sections of headers and footers, text boxes, content controls, fields, ... because Find Execute act on continuous range only.

 

I think that make it very difficult to have a function that can make all replacement. That being said I think it would be a nice addition to have an optional input to enable the replacement of text in the header and footer (or a separate vi).

 

Ben64

0 Kudos
Message 5 of 7
(3,125 Views)

Microsoft definitely has something tricky happening during a search/replace and apparently they don't want you to know.  I like to record macros to see what is going on under the hood but when I do that for a Find/Replace operation, the code given in the recorded macro doesn't accomplish the same task as the actions used to record the macro.  So in Word 2010 at least, there appears to be "bug" in recording macros. 

 

I'm not sure if this is the proper way but basically you need to activate the header, search it, activate the document, and search it.  This is not going to work in all instances because there are different header types (1st page only, current page, etc) and if a header doesn't exist when you try to activate it, you'll likely get an error.  If you have multiple header types, you could do this same operation several times and change the SeekView enum to a different value.  

 

headerSearch.png

 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 6 of 7
(3,104 Views)

I would do this for a document with different headers/footers.

 

Ben64

 

FindAndReplaceHeadersFooters.png

0 Kudos
Message 7 of 7
(3,090 Views)