LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save a Docx to doc

Solved!
Go to solution

Hi,

 

I am building a tool for our team. One of it's features should be the ability to change a docx file to doc, but so far I could not really figure out how to convert the file. I am using report generation toolkit for a few other features. 

 

I am not a pro in visual basic for aplications, but I made a macro that I insert and than remove with labview for an other purpose. So far I was not able to make a proper macro that saves the files as a doc withouth changing anything. 

 

Can someone recommend a solutiuon for this problem? Either a visual basic macro or a labview solution is fine or some guidence on how to solve it on my own. 

 

Much appreciated! Thanks in advance!

0 Kudos
Message 1 of 11
(4,571 Views)

If you have the Report Generation Toolkit, it takes three functions.  Generate a New Report, specifying Excel, and specifying the specific .doc file as the template (which really just means the file that Excel opens at the start and modifies, rather than starting with a blank WorkBook).  Now do a Save Report, specifying the same file, but with the .docx extension, followed by Dispose Report to turn off Excel.  To maximize the speed of this operation, you can specify "Minimized" in the New Report function to prevent Excel from "opening its Front Panel".  Don't forget to wire through the Error and Report Object lines.

 

Bob Schor

0 Kudos
Message 2 of 11
(4,570 Views)

The problem is that I already have a sort-of "template" document that I have to convert to doc if the extension is docx. The thing is, we get the files form an other department and some times they forget to change it to doc. There are other problems that we get these files and the tool has to correct it. Right now it corrects a lot of special characters that we do not allow in the documents etc. and than I dispose the report. 

 

I am thinking of a small stat machine before the other functions with get file extension, and if it is docx than I convert it to doc. This is what I am looking for. Sorry for not being obvious 

 

 

0 Kudos
Message 3 of 11
(4,567 Views)

Put these three functions inside a sub-VI, pass in a Path argument that ends in .doc, let the sub-VI "do its thing" and pass out the new Path argument that ends in .docx.

 

Don't get "hung up" on NI's term, "Template".  It is nothing "magic" -- if they had named it "Input File (Optional)", it would have been much less confusing.

 

On the other hand, you are asking Excel to do something more than simply rename a file for you -- you are potentially changing the file, as you may need to "give up" some of the features of the .docx format.  I'm not certain what hoops Excel will want you to jump through in order to accomplish this.

 

If this simple idea does not work for you, I recommend you respond to this post and include an example .docx file that needs to be "downgraded" to let us see "with real data" the nature of your problem.  Maybe we can come up with a fix ...

 

Bob Schor

Message 4 of 11
(4,565 Views)

If I understand you correctly, you say I have to make a "new" empty file and than put my stuff inside. Right now what I do is I open the specific file that I want to work on as the template file and do my stuff with it. At the end I want to convert it to a doc. Or before any other modifications are done. It does not really matter. Sadly I can not just use an empty file and copy all the stuff in, as this docx has a special template with about 300-400 special, custom advance properties linked all around the document with auto filling parts and whatever. 

 

Also, from the doc: 

"The reproduction, distribution and utilisation of this document as well as the

communication of its contents to others without express authorization is prohibited.

Offenders will be held liable for the payment of damages. All rights reserved in the

event of the grant of a patent, utility model or design."

 

I can not even make a dummy version of it to share it on the forums as it has some special company related info hardcoded in the file.

 

Either I realy misunderstand you, or you me, I am not sure now.

 

I know I change the file (Not sure what I change with the conversion, though) but if I do not convert it to doc, than it can not be used in an other tool as it was written in (I think) labview 7.0 and it can not have a docx as input file...

 

The tool I am working on though, can be used on any kind of document. I can show you my "dummy" test doc, but it only has some random characters, some "blabla" as general text and it is saved as a docx. That's all...  And it also has hardcoded company info. Any document I create on my company PC has this, sadly. So everything is classified 🙂 (funny thing)

 

 

By the way, I am not looking for a simple rename, I need a complete, real change from docx to doc. I was messing around with the SaveAs2 method for some time with no success as it was not working for some reason.... 

0 Kudos
Message 5 of 11
(4,561 Views)

I wonder if I get the file name with get file extension VI, and than use the save report to file VI which needs a path - and I set the path as the main folder with build path but with the original file name +.doc... Will it change it properly to a doc file?

0 Kudos
Message 6 of 11
(4,557 Views)
Solution
Accepted by topic author huntersoa

Oops, I made a silly mistake by talking about Excel.  You were discussing Word, not Excel, while I was "thinking" Excel yet saying ".doc" and ".docx".  However, I think the same principle should apply.  I gather you have not tried my suggestion of a "three-step process", nor my suggestion of posting a ".docx" sample for us to try, so I'm going to go through the steps, again, with explanation.  You don't have to try this -- you can just say "Thanks for trying to help, but I'm not going to listen to you".  I'll be disappointed, but not insulted ...

  1. Let's say your document is called "My Doc.docx".
  2. Do a "New Report", specifying "Word", with "My Doc.docx" as the "Template".  Note that this is not the same thing that Word means as a Word Template (a .dot or .dotx file) -- this is a LabVIEW term.
  3. Do a "Save Report to File", specifying the name "My Doc.doc" (not .docx).  You'll need the full File Path, of course.
  4. Dispose Report and end the program.

Try this.  If it doesn't work or does something unexpected, report back (and provide a sample .docx file!).  Or say "Sorry, I don't want to try your suggestion, but thanks for trying to help" and I'll stop trying to help you.

 

Bob Schor

Message 7 of 11
(4,553 Views)

Okay I made this real quickly, and it seems to be working. After the save it goes to the dispose vi. It created a new doc file but I am not entierly sure if it is really a proper doc file... 

0 Kudos
Message 8 of 11
(4,553 Views)

Hi again, and thanks a lot. I was dumb and did not really understand you at first. I think I did what you said and it seems to be working. I have a few problems with the real document though but I have to figure it out on my own. But this solution seems to be working on the dummy document. I hope it really became a doc file and not just the extension.

0 Kudos
Message 9 of 11
(4,549 Views)

Here is what you, via LabVIEW, told it to do:  Open a .docx file and do a "Save As", renaming it to .doc.  You (and LabVIEW) are asking Word to do the "translating" for you -- it is not your fault, not LabVIEW's fault, and certainly not my fault if Word screws up the document ...

 

I'm glad I was able to get you to understand what I was saying.  My tendency is to give "word" solutions rather than simply plunk down a VI -- my theory is that you learn better by "doing it yourself".

 

Bob Schor

Message 10 of 11
(4,543 Views)