XL98: Hyperlinks May Be Corrupted When Modified by a Macro

Last reviewed: February 3, 1998
Article ID: Q177888
The information in this article applies to:
  • Microsoft Excel 98 Macintosh Edition

SYMPTOMS

When you use a Microsoft Visual Basic for Applications macro or procedure to set the Address or SubAddress property of a hyperlink, the hyperlink's Name, Address, and SubAddress properties become corrupted.

Specifically, the properties contain underscores (___) or a combination of underscores and other characters instead of the correct values.

If you click the hyperlink, you may receive the following error message:

   Cannot open the specified file.

CAUSE

This problem occurs if you set the Address or SubAddress property of a hyperlink outside of the Add method of hyperlinks. For example, any of the following lines of code cause the problem:

   Sheets(1).Hyperlinks(1).Address = "NewAddress"
   Sheets(1).Hyperlinks(1).SubAddress = "NewSubAddress"

   mylink.Address = "NewAddress"
   mylink.SubAddress = "NewSubAddress"

Note that this problem does not occur in Microsoft Excel 97 for Windows.

WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

If you want to change the properties of an existing hyperlink, re-add the hyperlink in the same cell where it already exists, but specify different properties as needed. For example, if you want to change only the Address property of the existing hyperlink in cell A1 of Sheet1, you could use the following code:

   Sub ChangeAddress()

       ' Store the old hyperlink so you can get its properties.
       '
       Set oldLink = Worksheets("Sheet1").Cells(1, 1).Hyperlinks(1)

       ' Store the old Anchor and SubAddress properties. Note that the
       ' oldAddress line is optional and that the oldAnchor line must
       ' be preceded by "Set" since it is using a Range.
       '
       Set oldAnchor = oldLink.Range
       oldAddress = oldLink.Address
       oldSubAddress = oldLink.SubAddress

       ' Create the new link using the new Address and the original
       ' Anchor and SubAddress.
       '
       Set newLink = Worksheets("Sheet1").Hyperlinks.Add( _
           Anchor:=oldAnchor, _
           Address:="NewAddress", _
           SubAddress:=oldSubAddress)

   End Sub

You can use this method to change the Anchor, Address, and SubAddress properties of the hyperlink; just modify the "Set newLink =" line so that it uses the correct old properties and new properties.

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

In Microsoft Excel 97 for Windows and Microsoft Excel 98 Macintosh Edition, you can use a macro to create hyperlinks within a worksheet. To do this, you use the Add method of the Hyperlinks collection.

In Microsoft Excel 97 for Windows, you can also edit an existing hyperlink by setting the Address and SubAddress properties of the hyperlink to different values. If you attempt to do this in Microsoft Excel 98 Macintosh Edition, the hyperlink will become corrupted, and it will not work correctly when you click it.

REFERENCES

For additional information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q163435
   TITLE     : VBA: Programming Resources for Visual Basic for
               Applications


Additional query words: XL98
Keywords : kbcode kbprg IntLink xlvbainfo xlweb
Version : MACINTOSH:98
Platform : MACINTOSH
Issue type : kbbug
Solution Type : kbworkaround


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