Using Word 2007 features from version neutral PIA's

Add-in Express™ Support Service
That's what is more important than anything else

Using Word 2007 features from version neutral PIA's
More specifically saving a 2003 format doc in OpenXML format 
Bargholz Thomas




Posts: 242
Joined: 2006-12-18
Hi,
I have an add-in which runs on both Word 2003 and Word 2007. When in Word 2007, it will also do some conversion between classic .doc and openXML .docx formats - going both ways. So this is more of a Word question than an add-in-express question. But since you have extensive experience with this area, I hope you can help.

I need support for both Word 2003 and Word 2007, so I use the version neutral PIA's, which means that the OpenXML format is not part of the wdSaveFormat enum.
According to the documentation on MSDN (http://msdn.microsoft.com/en-us/library/bb238158.aspx) and a recorded macro, the right format wdFormatXMLDocument, which has a value of 12.
So in my call to Word SaveAs method, I pass the value 12 for OpenXML and the value wdFormatDocument for classic .doc.
Saving a blank document in OpenXML and saving between OpenXML documents works like a charm. Saving OpenXML as classic .doc works like a charm. However, when saving a classic .doc file as OpenXML, the resulting document is still classic .doc.

Are you aware of such an issue, perhaps related to the version neutral PIA's?

Here is the code I am using:

object fileName = filename;
object missing = System.Reflection.Missing.Value;
object False = false;
object True = true;
object SaveFormat = WdSaveFormat.wdFormatDocument;

switch (extension)
{
case "doc":
SaveFormat = WdSaveFormat.wdFormatDocument;
break;
default:
//http://msdn.microsoft.com/en-us/library/bb238158.aspx
SaveFormat = 12;
break;
}

Application.ActiveDocument.SaveAs(ref fileName, ref SaveFormat, ref missing, ref missing, ref False, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);


Best regards
Thomas
Posted 27 Nov, 2008 11:52:25 Top
Bargholz Thomas




Posts: 242
Joined: 2006-12-18
Just found part of the answer, but one that keeps the problem wide open.
By the magic of Google, I found a MVPS who had the same problem using pure VBA and Word 2007. He discovered, that you have to add a call to the Convert method. In my above samle like this:

Application.ActiveDocument.Convert();

The problem is, that this new method was added in Word 2007, so the Office neutral PIA's doesn't expose it.
So now my problem is that I need to have two set's of PIA's: Neutral for 2003 and 2007 for 2007. Is that easily handled by Add-in-express? If yes, how?

Best regards
Thomas
Posted 27 Nov, 2008 12:06:23 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Thomas,

You can use late binding:

Application.ActiveDocument.GetType().InvokeMember( ...


Andrei Smolin
Add-in Express Team Leader
Posted 27 Nov, 2008 12:35:54 Top
Bargholz Thomas




Posts: 242
Joined: 2006-12-18
Thanks, that worked like a charm =D

Just in case anyone else needs this feature, be aware that calling Convert fails if your document is already in OpenXML format.

Cheers,
Thomas
Posted 28 Nov, 2008 06:24:56 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Thank you, Thomas!

That's a really useful bit of info!


Andrei Smolin
Add-in Express Team Leader
Posted 28 Nov, 2008 06:40:50 Top