02-17-2016 09:57 PM
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?
Solved! Go to Solution.
02-18-2016 03:30 PM
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.
02-18-2016 03:38 PM
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.
Bob Schor
02-18-2016 07:30 PM
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
02-18-2016 07:51 PM - edited 02-18-2016 07:53 PM
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.
02-19-2016 07:35 AM
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
02-19-2016 08:32 AM
@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
02-19-2016 10:03 PM
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.
02-20-2016 08:56 AM
02-20-2016 09:13 AM
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