save as docx from office 2003

A

Andy Fish

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
 
D

Doug Robbins - Word MVP

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
 
A

Andy Fish

the converter can convert both ways - I have no problem saving docx files
interactively but just cannot do it from code
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Andy Fish

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
 
G

Graham Mayor

Sometimes the macro recorder comes up trumps ;)

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jesse

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
 
A

Andy Fish

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

Graham Mayor

As long as it works for you ..... ;)

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jonathan West

Andy Fish said:
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
 
S

Srini Kasturi

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.
 
M

Mary Pytosky

Hi,

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

Thanks ahead of time,
Mary
 
G

Graham Mayor

If Application.Version < 12 Then
ActiveDocument.SaveAs FileName:="filename.doc", wdFormatDocument
Else
ActiveDocument.SaveAs FileName:="filename.doc", wdFormatDocument97
End If

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Kevin T.

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
 
D

Doug Robbins - Word MVP

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top