WD2000: How to Use Other Converters with the FileFormat Property (209186)



The information in this article applies to:

  • Microsoft Word 2000

This article was previously published under Q209186

SUMMARY

The SaveAs method of the Document object in Microsoft Visual Basic for Applications has an optional parameter called FileFormat that you can use to specify the save format for the document.

This article describes how to use the FileFormat property of the SaveAs method to specify a converter that is not supported with one of the supplied constants (values).

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

The FileFormat optional variant (argument) specifies the format in which the document is to be saved and can be one of the following native (built-in) wdSaveFormat constants.

Constant

Description

 

 

wdFormatDocument

Saves as a Word document.

 

 

wdFormatHTML

Saves the file in HTML format (a Web page) so that it can be viewed in a Web browser.

 

 

wdFormatTemplate

Saves as a Word template.

 

 

wdFormatText

Text Only: Saves text without its formatting. Converts all section breaks, page breaks, and new line characters to paragraph marks. Uses the ANSI character set. Select this format only if the destination program cannot read any of the other available file formats.

 

 

wdFormatDOSText

MS-DOS Text: Converts files the same way as Text only format (wdFormatText). Uses the extended ASCII character set, which is the standard for MS-DOS-based programs. Use this format to share documents between Word and non-Windows-based programs.

 

 

wdFormatTextLineBreaks

Text only with line breaks: Saves text without formatting. Converts all line breaks, section breaks, and page breaks to paragraph marks. Use this format when you want to maintain line breaks; for example, when transferring documents to an electronic mail system.

 

 

wdFormatDOSTextLineBreaks

MS-DOS text only with line breaks: Saves text without formatting. Converts all line breaks, section breaks, and page breaks to paragraph marks. Use this format when you want to maintain line breaks; for example, when transferring documents to an electronic mail system.

 

 

wdFormatRTF

Rich Text Format (RTF): Saves all formatting. Converts formatting to instructions that other programs, including compatible Microsoft programs, can read and interpret.

 

 

wdFormatUnicodeText

Saves as a Unicode text file: Converts text between common character encoding standards, including Unicode 2.0, Mac OS, Windows, EUC, and ISO-8859 series.

Other File Types

If you record a macro that saves a file as a type that is not supported by one of the constants described earlier, the FileFormat property will contain a number. The following sample macro was recorded by using RFT-DCA as the Save As Type:

Sub Macro1()

      ActiveDocument.SaveAs FileName:="Doc1.rft", FileFormat:=101

End Sub
				
NOTE: The number 101 that was recorded for the RTF-DCA FileFormat argument is system specific. This number may not be the same on another computer.

To retrieve the correct FileFormat number for a conversion type for any computer, use the FileConverters collection. The following sample Visual Basic for Applications macro saves a document in RTF-DCA format on any computer.

NOTE: In the following sample, replace "RFTDCA" with the class name that you want to Save As. For a list of class names, see the "How to Obtain Class Names" section later in this article.

Sub SaveAsRFTDCA()

   Dim fcCnv As FileConverter
   Dim strClass As String
   Dim strFileName As String
   Dim x As String

   ' If there are no documents open to
   ' save, exit this routine.
   If Documents.Count = 0 Then Exit Sub

   ' Set the ClassName to use for saving.
   strClass = "RFTDCA"

   ' Set the FileName to use for saving.
   strFileName = "MyFile"

   ' Loop through all installed converters.
   For Each fcCnv In FileConverters

      With fcCnv

         ' Test for conversion ClassName.
         If .ClassName = strClass Then

            ' Save using the FileConverters.ClassName.
            ActiveDocument.SaveAs FileName:=strFileName, _
               FileFormat:=.SaveFormat
            x = "Saved"
               
         End If

      End With

   Next fcCnv

   If x = "Saved" Then

      ' If converter found, tell user document saved with converter.
      MsgBox "Your document has been saved in the " & Chr$(34) _
         & strClass & Chr$(34) & " format."
     
   Else

      ' If converter not found, tell user to install converter. 
      MsgBox "The " & Chr$(34) & strClass & Chr$(34) & _
         " converter is not installed. Please install it!"
 
   End If

End Sub
				
For more information about the SaveFormat property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type SaveFormat in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

How to Obtain Class Names

The following list contains converters and class names that are installed by Word and that you can use for saving a document.

Converter

ClassName

 

 

MS-DOS Text with Layout

MS-DOS Text with Layout

Text with Layout

Text with Layout

Word 2.x for Windows

MSWordWin2

Word 4.0 for Macintosh

MSWordMac4

Word 5.0 for Macintosh

MSWordMac5

Word 5.1 for Macintosh

MSWordMac51

WordPerfect 5.0

WrdPrfctDOS50

WordPerfect 5.1 for DOS

WrdPrfctDOS51

WordPerfect 5.x for Windows

WrdPrfctWin

WordPerfect 5.1 or 5.2 Secondary File

WrdPrfctDat

WordPerfect 5.0 Secondary File

WrdPrfctDat50

Works 4.0 for Windows

MSWorksWin4

Word 6.0/95

MSWord6Exp

Word 97-2000 & 6.0/95 - RTF

MSWord6RTFExp



To retrieve other class names for an installed converter to Save As, you can loop through the FileConverters collection.

The following sample macro loops through all installed converters that you can use for saving, and then it inserts the converter name and associated class name into a blank document:

Sub GetConvClassName()

   Dim fcCnv As FileConverter

   ' Create blank document.
   Documents.Add

   ' Loop through all installed converters.
   For Each fcCnv In FileConverters
      With fcCnv
         ' If the converter can be used to save...
         If .CanSave = True Then
            ' Insert the converter name and class name in the document.
            Selection.TypeText "Converter: " & .FormatName & vbTab _
            & "ClassName: " & .ClassName & vbCr
         End If

      End With

   Next fcCnv

End Sub
				
For more information about the ClassName property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type ClassName in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

REFERENCES

For additional information about the text converters included with the Microsoft Office 2000 Setup or the Microsoft Office Converter Pack, click the article number below to view the article in the Microsoft Knowledge Base:

235928 WD2000: Supported File and Graphics Formats

For additional information about getting help with Visual Basic for Applications, click the article numbers below to view the articles in the Microsoft Knowledge Base:

212623 WD2000: Macro Programming Resources

226118 OFF2000: Programming Resources for Visual Basic for Applications


Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbconversion kbdtacode kbhowto KB209186