Incorrect Argument with Recorded OpenLinks Method (115693)



The information in this article applies to:

  • Microsoft Excel for Windows 95 7.0a
  • Microsoft Excel for Windows 5.0a

This article was previously published under Q115693

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


Modification Type:MinorLast Reviewed:8/15/2003
Keywords:KB115693