WD: Using FileSaveAs to Save Files to Another File Format

Last reviewed: November 17, 1997
Article ID: Q90747
The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0
  • Microsoft Word for the Macintosh, versions 6.0, 6.0.1

SUMMARY

The Microsoft WordBasic FileSaveAs command allows you to save the current file to another file format and/or to another filename. The syntax for the FileSaveAs command is as follows:

Word 7.0

   FileSaveAs [.Name = text][,.Format = number][,.LockAnnot =
   number][,.Password = text][,.AddToMru = number][,.WritePassword =
   text][,.RecommendReadOnly = number][,.EmbedFonts =
   number][,.NativePictureFormat = number][,.FormsData =
   number][,.SaveAsAOCELetter = number]

Word 6.0

   FileSaveAs [.Name = text][,.Format = number]
   [,.LockAnnot = number][,.Password = text]
   [,.WritePassword = text][,.AddToMru = number]
   [,.RecommendReadOnly = number]

Word 2.x

   FileSaveAs [.Name = text][,.Format = number]
   [,.LockAnnot = number][,.Password = text]

The following command saves the active document in rich-text format (RTF) under the name TEST.RTF for Word 2.x or Word 6.0:

   FileSaveAs .Name = "TEST.RTF", .Format = 6

To specify a directory other than the current directory, indicate the full path with the document name parameter.

Note: When you use the FileSaveAs statement in a macro, if an existing file has the same name, it will be automatically overwritten unless it was previously a template.

The following six formats are internal to Word for Windows (2.x & 6.0) and can be set using the .Format parameter:

   0   Normal (Word format)
   1   Document Template
   2   Text Only (extended characters saved in ANSI
       character set)
   3   Text+Breaks (plain text with line breaks; extended
       characters saved in ANSI character set)
   4   Text Only (PC-8) (extended characters saved in IBM PC
       character set)
   5   Text+Breaks (PC-8) (text with line breaks; extended
       characters saved in IBM PC character set)
   6   Rich-text format (RTF)

You can specify additional file formats.

The Word ConverterLookup() function returns the appropriate format number for the specified file format. You can specify the file format by using the class name or the format name as it appears in Word 7.0 on-line Help. Search the topic name "Class names of file converters". You can specify the file format in Word 6.0 by using the class name or the format name as it appears in the Save File as Type box in the Save As dialog box (File menu).

To save a document to the WordPerfect 5.1 file format and the name "test.wp", use the following WordBasic instructions:

Word version 7.0

   Sub MAIN
      x = ConverterLookup("WordPerfect 5.1 for DOS")
     FileSaveAs .Name = "test.wp", .Format = x
   End Sub

Word version 6.0

   Sub MAIN
      x = ConverterLookup("WordPerfect 5.1 for MS-DOS")
      FileSaveAs .Name = "test.wp", .Format = x
   End Sub

Word version 2.0

In Word 2.x, to indicate a format other than the six internal formats you can count the first converter listed under the [MS Text Converters] section as number 7 or 100 and then count down the list. For example, based on the following WIN.INI settings, the WordPerfect 5.1 converter can be counted as format 103 or 10.

   [MSWord Text Converters]
   DOS Text with Layout=DOS Text with Layout,C:\WINWORD\TXTWLYT.CNV, asc
   Text with Layout=Text with Layout,C:\WINWORD\TXTWLYT.CNV,ans
   WrdPrfctDOS50=WordPerfect 5.0, C:\WINWORD\WPFT5.CNV, doc
   WrdPrfctDOS=WordPerfect 5.1, C:\WINWORD\WPFT5.CNV, doc

To save a document to the WordPerfect 5.1 file format and the name "test.wp", use either of the following commands based on the WIN.INI settings above:

   FileSaveAs .Name = "test.wp", .Format = 103

MORE INFORMATION

The following example macro saves the current document to the text file format with a .TXT file extension:

   Sub Main
      fname$ = FileName$()
      fname$ = Left$(fname$,( InStr(fname$, ".")- 1))
      FileSaveAs fname$ + ".TXT", .Format = 2
   End Sub

The Left$() command above separates the document name from its file extension so that the macro can save the document as a text file with a .TXT extension. InStr() is used to determine the position of the "." character. Left$() is then used to return all the characters to the left of the "." character. The FileSaveAs command saves the document in the text- only format with a .TXT file extension in the active directory. Note: This sample won't work if the file has not previously been saved.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 208


Additional query words: winword2 word95 File Save Format File winword
macword word7 word6
Keywords : macword winword
Version : Windows: 2.x 6.0 6.0a 6.0c 7.0;
Platform : MACINTOSH WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.