XL: Incorrect Argument with Recorded OpenLinks Method

Last reviewed: September 13, 1996
Article ID: Q115693
The information in this article applies to:
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel for Windows, versions 5.0, 5.0a

SYMPTOMS

In Microsoft Excel, if you use the macro recorder to record a Visual Basic macro, and you choose the Open button in the Links dialog box to open a linked document, the OpenLinks method is recorded with an incorrect ReadOnly argument if the link is an object linking and embedding (OLE) link.

Note that this behavior does not cause an error message to appear when you run the macro. The recorded macro runs correctly.

CAUSE

When you record a Visual Basic macro, where you use the Open button in the Links dialog box to open an OLE link, the OpenLinks method is recorded with a ReadOnly argument value of 2. For example, if you use the macro recorder to open a linked Microsoft Word document, C:\DOCUMENT\REPORT.DOC, the recorded macro contains the following command:

   ActiveWorkbook.OpenLinks Name:= _
      "Word.Document.6|C:\DOCUMENT\REPORT.DOC!!DDE_LINK1", ReadOnly:=2

This value is incorrect, because the ReadOnly argument should have a value of True or False (Boolean value). However, the recorded macro runs correctly, because the recorded argument is accepted as the type argument. The value 2, used with the type argument, indicates an OLE type link (xlOLELinks).

The following is the command that should be recorded when you open the linked Microsoft Word document, C:\DOCUMENT\REPORT.DOC, using the Open button in the Links dialog box (although it has the same behavior as the incorrect code above):

ActiveWorkbook.OpenLinks Name:= _

      "Word.Document.6|C:\DOCUMENT\REPORT.DOC!!DDE_LINK1", Type:=2

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

You can use the OpenLinks Method in a Visual Basic macro to open a file that contains information that is linked to your Microsoft Excel worksheet. The file may be another worksheet, or a document in another application, such as a Microsoft Word document.

The OpenLinks method has the following named arguments: name, readOnly, and type. Name is the only required argument. However, if you only use the name argument, the link type is assumed to be xlExcelLinks. If you omit the type argument, and the link type is OLE, you receive a "Cannot find <filename>" error message and the linked file is not opened.

REFERENCES

For more information about the OpenLinks Method, choose the Search button in the Visual Basic Reference and type:

   OpenLinks Method


KBCategory: kbusage
KBSubcategory:

Additional reference words: 1.00 5.00 5.00a 5.00c 7.00 7.00a



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: September 13, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.