Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Format Parameter for Word Automation Document SaveAs method ?

171 views
Skip to first unread message

PRMARJORAM

unread,
Oct 7, 2009, 9:07:01 AM10/7/09
to
Hi,

Im using WORD automation from an MFC client app using VS 2005.
I can successfully start WORD and open an existing word document.

What I want to then do is save it in a different format via the SaveAs
method on the Document object and where the second parameter is the format to
save-as.
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdsaveformat.aspx

My problem is specifiying this parameter - as takes a variant, in the
documentation need to specifiy and enum of WdSaveFormat but this is not in
any of my word files
generated from create class from typlib where i selected just what i thought
i needed Application and Document objects.

Basically how to specify the format parameter for the SaveAs method relative
to the enum values specified in the documentation link above?

Thanks

AliR

unread,
Oct 7, 2009, 11:21:22 AM10/7/09
to
I looked it up through OLE/COM Object Viewer.

typedef enum {
wdFormatDocument = 0,
wdFormatDocument97 = 0,
wdFormatTemplate = 1,
wdFormatTemplate97 = 1,
wdFormatText = 2,
wdFormatTextLineBreaks = 3,
wdFormatDOSText = 4,
wdFormatDOSTextLineBreaks = 5,
wdFormatRTF = 6,
wdFormatUnicodeText = 7,
wdFormatEncodedText = 7,
wdFormatHTML = 8,
wdFormatWebArchive = 9,
wdFormatFilteredHTML = 10,
wdFormatXML = 11,
wdFormatXMLDocument = 12,
wdFormatXMLDocumentMacroEnabled = 13,
wdFormatXMLTemplate = 14,
wdFormatXMLTemplateMacroEnabled = 15,
wdFormatDocumentDefault = 16,
wdFormatPDF = 17,
wdFormatXPS = 18,
wdFormatFlatXML = 19,
wdFormatFlatXMLMacroEnabled = 20,
wdFormatFlatXMLTemplate = 21,
wdFormatFlatXMLTemplateMacroEnabled = 22,
wdFormatOpenDocumentText = 23
} WdSaveFormat;


Open Object Viewer, select File/View TypeLib... Then select the MSWord.OLB,
you can find the directory in the same dialog where you create your classes
from a typelib. When the ITypeLib Viewer opens select View/Group by type
kind, if not already selected. Expand the Enums tree item, and search down
for the enum you are looking for.


AliR.


"PRMARJORAM" <PRMAR...@discussions.microsoft.com> wrote in message
news:C71B419F-B354-407B...@microsoft.com...

Scott McPhillips [MVP]

unread,
Oct 7, 2009, 11:46:38 AM10/7/09
to
I don't use create class from typelib, but it does get the enums if you do
it with #import.

#define _MSWORDOLB_PATH "C:\Program Files\Microsoft
Office\OFFICE12\MSWORD.OLB"
#import _MSWORDOLB_PATH rename("ExitWindows", "WordExitWindows")
rename("FindText", "WordFindText") raw_interfaces_only
using namespace Word;

This creates the file msword.tlh which includes, among many other things,
this declaration:

enum WdSaveFormat

};

"PRMARJORAM" <PRMAR...@discussions.microsoft.com> wrote in message
news:C71B419F-B354-407B...@microsoft.com...

--
Scott McPhillips [VC++ MVP]

PRMARJORAM

unread,
Oct 7, 2009, 11:49:01 AM10/7/09
to
Excellent thanks for that.

It turns out also when generating the class from the typelib a msword.tlh
file is also generated containing all these enums and their values.

I could not include this directly though as got loads of compiler errors but
it does contain the values you need.

0 new messages