Microsoft KB Archive/96264

{|
 * width="100%"|

WD: FileSaveAs Macro Causes Error Message in Word Document Object

 * }

Q96264

-

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

-

SYMPTOMS
In Word versions 2.x through 6.x, if you execute the FileSaveAs command from a WordBasic macro while editing a Word Document Object, the following error message occurs, regardless of the file name specified:

This is not a valid filename.

Word for Windows version 7.x does not issue an error message.

For example, the following macro command causes this error message:

FileSaveAs .name=&quot;test.doc&quot;

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

Use the WindowName$ function to determine if the active document is an embedded Word document object. If the active document window is not an embedded Word document object, the file is saved. Otherwise, the macro uses the SendKeys command to use the Save Copy As command(On the File menu) to save editing changes made to the embedded document object to the original document.

  Sub MAIN a$ = WindowName$ ' If the active document is the embedded document. If InStr(a$, &quot;Document in&quot;) <> 0 Then ' The following sequence of commands are sent using SendKeys: '        ' File ' Save Copy As        ' Name of file to save to         ' OK(Enter or Return) ' (y)es-overwrite the file '        SendKeys &quot;%f&quot; : SendKeys &quot;a&quot; : SendKeys &quot;C:\test.doc&quot; : \ SendKeys &quot;{ENTER}&quot; : SendKeys &quot;y&quot; Else ' Otherwise, save the document. FileSaveAs .Name = &quot;test.doc&quot; End If  End Sub Note: Use SendKeys only when there is no alternative, and then use it with caution. You should test even the simplest use of SendKeys under a variety of conditions to avoid unpredictable results, data loss, or both. When stepping through a macro (using the Step or Step Subs button on the Macro toolbar) that contains a SendKeys instruction, note that the macro will not perform as expected unless the SendKeys instruction and the instruction that activates the target application or dialog box are on the same line, separated by a colon.

MORE INFORMATION
If you execute the FileSaveAs command by choosing Save As from the File menu, Word saves the object as a Word document. You cannot perform the same operation using a WordBasic macro.

By contrast, the FileSave command behaves the same regardless of whether you execute the command from a macro or by choosing Update from the File menu (the Save command changes to Update while editing a Word Document Object).

Additional query words: ole embed

Keywords : kbmacro kbole wordnt word6 winword2 word7 word95

Issue type : kbprb

Technology :