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

save as docx from office 2003

23 views
Skip to first unread message

Andy Fish

unread,
Aug 28, 2007, 1:00:26 PM8/28/07
to
Hello,

I am trying to automate word 2003 to save a doc file as docx (I have the
converter installed). I am actually using C# but I think the question would
equally apply to all environments

according to the documentation for word 2007, FileFormat parameter should be
set to wdFormatXMLDocument which has the value 12. However, this did not
work for me.

is there any way to get this to work for word 2003?

Andy


Doug Robbins - Word MVP

unread,
Aug 28, 2007, 3:43:09 PM8/28/07
to
I am not aware of a converter that will allow 2003 to produce docx files. I
believe that it works the other way. That is, it converts docx to the
previous file format.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Andy Fish" <ajf...@blueyonder.co.uk> wrote in message
news:Om$4dUZ6H...@TK2MSFTNGP02.phx.gbl...

Andy Fish

unread,
Aug 28, 2007, 5:21:41 PM8/28/07
to
the converter can convert both ways - I have no problem saving docx files
interactively but just cannot do it from code

"Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org> wrote in message
news:eHFysua6...@TK2MSFTNGP02.phx.gbl...

Graham Mayor

unread,
Aug 29, 2007, 2:12:17 AM8/29/07
to
In Word vba - Try

If Application.Version <> 12 Then
ActiveDocument.SaveAs FileName:="filename.docx", FileFormat:=109
Else
ActiveDocument.SaveAs FileName:="filename.docx", FileFormat:=12
End If


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org

Andy Fish

unread,
Aug 29, 2007, 4:17:21 AM8/29/07
to
Thanks graham, I'll give that a go

BTW can you tell me where you got the value 109 from? I can't find it in any
documentation

Andy

"Graham Mayor" <gma...@REMOVETHISmvps.org> wrote in message
news:OvCfoSg...@TK2MSFTNGP06.phx.gbl...

Graham Mayor

unread,
Aug 29, 2007, 6:00:47 AM8/29/07
to
Sometimes the macro recorder comes up trumps ;)

Jesse

unread,
Aug 29, 2007, 11:56:27 AM8/29/07
to
As someone who has (almost) no macro-writing skills so I use the
recorder all the time and then tweak the code, hit-or-miss, and seeing
that you are a Word MVP, I think that is a very funny observation.
As if Bill Gates had a problem with his PC and got it working with a
simple twak to the side of the box. Thanks. - Jesse

Andy Fish

unread,
Aug 30, 2007, 4:30:53 AM8/30/07
to
thanks graham - that's a great tip :-)

"Graham Mayor" <gma...@REMOVETHISmvps.org> wrote in message

news:eUyxyNi...@TK2MSFTNGP06.phx.gbl...

Andy Fish

unread,
Aug 31, 2007, 9:28:12 AM8/31/07
to
BTW when I tried it with the macro recorder I actually got the value 100
which is the value I have used.

"Graham Mayor" <gma...@REMOVETHISmvps.org> wrote in message

news:OvCfoSg...@TK2MSFTNGP06.phx.gbl...

Graham Mayor

unread,
Aug 31, 2007, 10:00:50 AM8/31/07
to
As long as it works for you ..... ;)

Jonathan West

unread,
Sep 7, 2007, 8:10:12 PM9/7/07
to

"Andy Fish" <ajf...@blueyonder.co.uk> wrote in message
news:eMHa6L9...@TK2MSFTNGP05.phx.gbl...

> BTW when I tried it with the macro recorder I actually got the value 100
> which is the value I have used.
>
>

With external converters (which is what the docx converter is implemented
as) the number to use for the SaveAs will vary from PC to PC depending on
what other converters are also installed.


If you want to have code which will correctly Save As docx on any PC, then
you need to dynamically find the number to use for the SaveAs command. This
can be found by reading the SaveFormat property of the appropriate
FileConverter object.

The following macro (adapted from one in the VBA Help) lists all the file
converters on your PC, give the class name, friently name, and the
SaveFormat number.

Sub FileConverterList()
Dim cnvFile As FileConverter
Dim docNew As Document

'Create a new document and set a tab stop
Set docNew = Documents.Add
docNew.Paragraphs.Format.TabStops.Add _
Position:=InchesToPoints(3)

'List all the converters in the FileConverters collection
With docNew.Content
.InsertAfter "Class" & vbTab & "Name" & vbTab & "Number"
.InsertParagraphAfter
For Each cnvFile In FileConverters
If cnvFile.CanSave = True Then
.InsertAfter cnvFile& vbTab & cnvFile.FormatName & vbTab & _
cnvFile.SaveFormat
.InsertParagraphAfter
End If
Next
.ConvertToTable
End With

End Sub

From running this, it is possible to deduce that the class name we are
interested in is "Word12"

Therefore, in order reliably get the save format number, use this function

Function GetSaveFormat(sClassname As String) As Long
Dim cnvFile As FileConverter

For Each cnvFile In FileConverters
If cnvFile.ClassName = sClassname Then
If cnvFile.CanSave = True Then
GetSaveFormat = cnvFile.SaveFormat
Exit Function
End If
End If
Next cnvFile

End Function


To use the function to save a document as docx, proceed as follows

Dim iSaveFormat As Long
iSaveFormat = GetSaveFormat("Word12")
If iSaveFormat = 0 Then
MsgBox "Word 2007 file converter is not installed"
Else
ActiveDocument.SaveAs FileName:="filename.docx", FileFormat:=iSaveFormat
End If

Srini Kasturi

unread,
Jun 13, 2008, 10:49:02 AM6/13/08
to
Is there a batchfile command line mode for word to save a file in differnet
formats.

I am VB ignorant and was looking for a way to save doc in txt format through
a call to a batch file - so I can call it from within Java.

Appreciate any help.

Pytosky@discussions.microsoft.com Mary Pytosky

unread,
Sep 5, 2008, 4:54:17 PM9/5/08
to
Hi,

What would be the code/Fileformat to change the document to be saved as an
Office 2003 document?

Thanks ahead of time,
Mary

Graham Mayor

unread,
Sep 6, 2008, 1:24:31 AM9/6/08
to
If Application.Version < 12 Then
ActiveDocument.SaveAs FileName:="filename.doc", wdFormatDocument
Else
ActiveDocument.SaveAs FileName:="filename.doc", wdFormatDocument97

Janie

unread,
Sep 28, 2008, 4:08:00 PM9/28/08
to

How can I open a docx file when I have Microsoft word 2003

T.@discussions.microsoft.com Kevin T.

unread,
Dec 29, 2009, 9:47:01 AM12/29/09
to
Hello,

Thanks for the forum. I am trying to save a document that has been created
in word 2003. I believe it is initially a .RTF file and we want to then save
it as a word 2000 .doc. Without going into much detail about why, we have
noticed that the new 2003 files when converted from .RTF to .doc increase the
size of the file muich more that 2000 did. One of our apps. do not like it.

I really like the idea Graham provided for what I am trying to accomplish.
However, I am not sure what I should change. I am guessing we need to make a
change at the " wdFormatDocumentXX "?

Regards,
Kevin

Doug Robbins - Word MVP

unread,
Dec 29, 2009, 5:26:30 PM12/29/09
to
The code that Graham provided was to allow a document to be saved in Word
97-2003 format regardless of whether the version of Word was 2007 (Version
12) or an earlier version .

There is no difference in the file format of files created in any of the
following versions and you cannot save a document in Word 2000 format as
there is no such thing.

Word 97
Word 2000
Word XP (2002)
Word 2003

If you are using Word 2003, the command to save the document as a Word
document (the format used for Word 97-2003) is ActiveDocument.SaveAs

FileName:="filename.doc", wdFormatDocument

I do not know where the "initially a .RTF file" comes into the picture.
However, if you did want to save in that format, you would use

ActiveDocument.SaveAs FileName:="filename.rtf", wdFormatRTF

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Kevin T." <Kevin T.@discussions.microsoft.com> wrote in message
news:38FFCA31-1DA7-4F25...@microsoft.com...

0 new messages