Microsoft KB Archive/90747

{|
 * width="100%"|

WD: Using FileSaveAs to Save Files to Another File Format

 * }

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, 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 = &quot;TEST.RTF&quot;, .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 &quot;Class names of file converters&quot;. 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 &quot;test.wp&quot;, use the following WordBasic instructions:

Word version 7.0
  Sub MAIN x = ConverterLookup(&quot;WordPerfect 5.1 for DOS&quot;) FileSaveAs .Name = &quot;test.wp&quot;, .Format = x  End Sub

Word version 6.0
  Sub MAIN x = ConverterLookup(&quot;WordPerfect 5.1 for MS-DOS&quot;) FileSaveAs .Name = &quot;test.wp&quot;, .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 &quot;test.wp&quot;, use either of the following commands based on the WIN.INI settings above:

  FileSaveAs .Name = &quot;test.wp&quot;, .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$, &quot;.&quot;)- 1)) FileSaveAs fname$ + &quot;.TXT&quot;, .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 &quot;.&quot; character. Left$ is then used to return all the characters to the left of the &quot;.&quot; 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 &quot;as is&quot; 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.