ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

取消
显示结果 
搜索替代 
您的意思是: 

Using Word Insert Field VI to load a bookmark

已解决!
转到解答

I'm using a VI from the MS Word/Excel Report Generation toolkit called Word Insert Field.  I have an MS Word document with a named bookmark.  I want to replace the bookmark text programmatically from LabVIEW.  I believe WordInsert Field is the right VI, but I can't find the proper input for type- there are something like 100 choices.  I just want to replace the bookmark text with the text I have provided in the text input.  Should be simple...

 

In the example in the attached file, I'm trying to insert the text "XXX1234" at the bookmark named LotNum in the Word file BookTest.docx.  I don't know what to choose for the type constant.  There are many choices, and none I've tried work correctly.

 

 

0 项奖励
1 条消息(共 6 条)
5,095 次查看

I use the VI "Append Report Text.vi" instead of "WordInsert Field.vi" to do what you want and it works as intended (see code below).

 

Example_VI_BD.png

 

 

 

Marc Dubois
0 项奖励
2 条消息(共 6 条)
5,082 次查看

MD:

 

Thanks for the suggestion.  Append Report Text does indeed insert the desired text at the bookmark location, but it doesn't replace the existing text that I've defined as the bookmark.  It just appends.  I want to programmatically update the contents of the bookmark (lot number, in this case) and then save the document with the updated text.  So I think (hope) Word Insert Field is the right VI.

0 项奖励
3 条消息(共 6 条)
5,062 次查看
解答
接受人 markwni

I have been able to replace existing text at a bookmark using Labview. My solution uses Word macros. In the Word template you use for your document, you create a Word macro that locates the bookmark you want. It is easier to create a macro for each bookmark but I think that you can pass the bookmark name as a parameter but it is not my area of expertise. Then, you create another macro that just deletes the number of characters you want to erase (once again, you can probably pass the number of characters as a parameter if you are a passable Word macro programmer). Then, you insert the new text at the bookmark. See code below.

 

There might be another way to do it using the various sub-VIs within the Append Report Text.vi but I have not been able to figure out so far.

 

Bookmark_replacement_BD.png

Marc Dubois
0 项奖励
4 条消息(共 6 条)
4,971 次查看

md:

 

Thanks for the suggestion.  Great idea, using macros to replace the text.  I hadn't thought of that.  I will give it a try.  I really appreciate your help.

 

Scott

0 项奖励
5 条消息(共 6 条)
4,952 次查看

md:

 

Oops, I marked my reply as a solution, when I intended to mark your reply as the solution.  Sorry about that.  I do appreciate your help, and you certainly deserve credit for the help you've given me.  Chalk it up to me being a beginner user of the formus...  thanks again.

 

Scott

0 项奖励
6 条消息(共 6 条)
4,945 次查看