LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Title to Word Report that it will Default Save-As

Solved!
Go to solution

I am trying to create a new Word report from a template file that will fill in the title property automatically and have that be the default valued entered when the user hits "Save".  I have tried setting it in "Word Document Properties" by setting the title field.  It does set the title, but Word does something weird.  The first time you hit save, it puts the first line of text as the file name (like it would for any new document with a blank title property).  If you hit cancel, then hit save again, it will use the title given in the title property.  Is this a weird Word thing, or is there some way to force it to work like I want it to?

0 Kudos
Message 1 of 18
(4,480 Views)

Sounds really strange.  Could you attach a screenshot of your code?  Maybe one of the properties is set wrong or the program execution order isn't being enforced.

0 Kudos
Message 2 of 18
(4,423 Views)

When you use the Report Generation Toolkit, you need to let LabVIEW handle all of the File I/O, i.e. keep your hands off Word.  The following (almost trivial) code opens a blank Word Document, sets the Title to "Test Title", then saves it under a different name before exiting.  It works as you would want it to work.

Word Title.png

Bob Schor

 

0 Kudos
Message 3 of 18
(4,420 Views)

OlenAnderson a écrit :

I am trying to create a new Word report from a template file that will fill in the title property automatically and have that be the default valued entered when the user hits "Save".  I have tried setting it in "Word Document Properties" by setting the title field.  It does set the title, but Word does something weird.  The first time you hit save, it puts the first line of text as the file name (like it would for any new document with a blank title property).  If you hit cancel, then hit save again, it will use the title given in the title property.  Is this a weird Word thing, or is there some way to force it to work like I want it to?


I'm not able to reproduce it. It works just fine for me (are you using a .dotx file for your template?).

Can you share yopur code? Are you using ActiveX or the RGT?

 

Ben64

0 Kudos
Message 4 of 18
(4,403 Views)

The code is pretty basic- create new Word file from template, insert a bunch of text, then a bunch of pictures, then "Word Bring to Front" (which doesn't do what I wanted it to do, I thought it would make Word the top application), then set the title, then that's it.  Because a test may have bad results, it wouldn't be a good idea to automatically save it (the data is all stored in a seperate text file).

 

Bob, you manually saved the file with that name, but what I want to do is have the title populated correctly automatically when the user hits the save button.  For example, in the other screenshot below, "Cycle Test Report" is the first line of text in the document, but the title given to "Word Document Properties" was "cycletest".  And the Word document does indeed have "cycletest" as its title, when you look at properties.  If I close the Save As dialogue, then relaunch it, it does have "cycletest.docx" as the name.

 

 

 

 

save.PNG

 

Capture.PNG

0 Kudos
Message 5 of 18
(4,390 Views)

Can you attach the VI that you illustrate in your post?  I'm not sure I completely understand what you are trying to do, so I'd like to "test" your code and try to modify it so that it does what you want.  However, it is much too much work for me to try to go from your image of your code to executable LabVIEW code (do you know about Snippets?).

 

Bob Schor

0 Kudos
Message 6 of 18
(4,355 Views)

@SmithGo wrote:

I am trying to create a new Word report from a template file that will fill in the title property automatically and have that be the default valued entered when the user hits "Save".  I have tried setting it in "Word Document Properties" by setting the title field.  It does set the title, but Word does something weird.  The first time you hit save, it puts the first line of text as the file name (like it would for any new document with a blank title property).  If you hit cancel, then hit save again, it will use the title given in the title property.  Is this a weird Word thing, or is there some way to force it to work like I want it to?


My guess would be that the document properties are set when you save the document. So when you first press save it uses the default first text line as the title while setting the title properties. When you press save for the second time Word then use the Title property value that was set by the first save.

 

As a workaround either you use Save Report To File.vi as in Bob example or you set the title property manually in the Word Template (assuming you always want to use the same title).

 

Ben64

0 Kudos
Message 7 of 18
(4,344 Views)

My code is over-complicated for what I'm trying to show.  I have attached a file that dmonstrates what I mean, although you'll have to have your own Word Template.  The Word Template needs one line of text in it at least.  When you hit save, the default name enetered to Save As will have at least part of that line of text entered as the name.  Hit cancel, then save again and it will have the title you entered in the VI.

0 Kudos
Message 8 of 18
(4,312 Views)

Have a look at this link.

 

Ben64

Message 9 of 18
(4,292 Views)

Wow, Ben, how do you find these obscure "Feature Reports"?  I'm glad to see that yet another "LabVIEW Failing" is not NI's fault, but is a flaw buried within Microsoft Office ...

 

Bob Schor

0 Kudos
Message 10 of 18
(4,279 Views)