LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

word save as txt with line breaks

Is there a way to save a Word document as text (.txt extension) with linebreaks?

If I use the WordReport DocumentSaveAs function, I don't see that I have the chance to specify that I want line breaks inserted.

When I save a Word doc as txt in Word 2003, I get a popup asking if I want line breaks and if so, what they should be (lf, crlf, cr, etc.)

Then again will WordReport even work with Word 2003? 

Could I use a Macro to do this?

Menchar
0 Kudos
Message 1 of 8
(4,352 Views)
 

Howdy Menchar,

The Microsoft Word shipping examples that come with LabWindows/CVI are built using the Microsoft Word 2000 Automation Server (9.0) which at the time didn't expose the line breaks option for the SaveAs method. However, the Microsoft Word 2003 (11.0) object model documentation shows that the new SaveAs method does support this feature (Refer to the SaveAs Method.jpg attachment which is a snapshot taken from the help file VBAWD10.CHM located at C:\Program Files\Microsoft Office\OFFICE11\1033\.  Find more information about object model documentation at How to find and use Office object model documentation).

I then went back into LabWindows/CVI and created a new ActiveX controller for Microsoft Word 2003 by using the ActiveX Controller Wizard. After creating this, I verified that the new SaveAs method for a Document object included this new feature.  See the differences between the function panels for Word 2000 and 2003 in the attachments entitled Microsoft Word 9.0.jpg and Microsoft Word 11.0.jpg. Notice there is some additional fields including one for line breaks.

Hope this helps!

Best Regards, 

Jonathan N.
National Instruments
0 Kudos
Message 2 of 8
(4,328 Views)
Jonathan -
 
Thanks for the reponse!  And thanks especially for the good links into the MS documentation, that's half the battle right there.
 
I managed to hack out a Word 2003 macro which uses the SaveAs method that includes the linebreaks feature.  I think I should be able to invoke this from CVI using WordReport's RunMacro function.  If this fails, I'll do as you suggest and make a Word 2003 ActiveX controller.  The Word 2003 ActiveX controller would be cleaner - but will the Word Report functions break if used with a Word 2003 ActiveX controller?  I seem to recall seeing something about this on the forum.
 
Thanks again Jonathan, good job.
 
Menchar
0 Kudos
Message 3 of 8
(4,325 Views)

Hi Menchar,

To ensure compatibility, you want to make sure that when you create the Microsoft Word 2003 ActiveX controller, you use the same instrument prefix and the same Compatibility Options.  You will see these options when you use the wizard.

Best Regards,

Message Edited by Jonathan N on 10-13-2006 01:20 PM

Jonathan N.
National Instruments
0 Kudos
Message 4 of 8
(4,324 Views)
Well, I created the ActiveX controler for Word 2003 all OK, and I do indeed have access to the SaveAs method with linebreak option, but what a pain marshalling all of the parameters into the ActiveX data types.   The relationship between C and ActiveX datatypes, how to convert, how to declare in C, etc. didn't exactly leap out at me from the help info.  Examples in VB don't help much if you're hacking out C code.

Even how to assign a C string to a variant (for the filename) wasn't obvious to me.

What I wanted to be able to do was save a .doc as a .txt with linebreaks in a different folder from the original .doc file.

While I could parameterize the VB macro itself within Word, i couldn't pass a parameter to it using the WordReport run macro function.

So I went the easier but less preffered route of just ihardcoding the destination folder into the macro.

If I had gotten the ActiceX SaveAs method working, I could specify the full pathname to the saveas method.

Oh well.
0 Kudos
Message 5 of 8
(4,303 Views)

Hi menchar,

 

I definitely agree with you that it can sometimes be "stressful" to convert back and forth between ActiveX and C data types. You probably already found this out, but all the ActiveX conversion functions are located in the ActiveX Library located in the Library Tree

 

I would recommend taking a look at the Word2000demo shipping example that demonstrates some more Word automation and the usage of some more conversion function. In regards to you being able to save in a different located, notice our Save button and its callback function. We pop up a dialog asking for a file name and location. We then pass that onto Word's SaveAs method for a filename.  This might help you out.

 

If you can think of any better way to make ActiveX and C data type conversion easier for the user, I would definitely submit a product suggestion (Goto www.ni.com >> Contact NI >> Product Feedback)


Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 6 of 8
(4,279 Views)
 

Howdy menchar,

I would also recommend taking a look at the tutorial entitled LabWindows/CVI ActiveX Controller For Visual Basic 6.0 Users.

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 7 of 8
(4,273 Views)
Joathan -

Thanks for the links to the tutorial info.  I was trying to get this going without making several hours investment researching how ActiveX works with CVI.

I was starting to think about how this might have been handled more cleanly within CVI, but don't have anything in mind as yet.  It's the variant that gums things up I think.

I'd still like to use the ActiveX server to do this, if I have the time I'll come back to it.

Menchar
0 Kudos
Message 8 of 8
(4,267 Views)