Microsoft KB Archive/177888

= XL98: Hyperlinks May Be Corrupted When Modified by a Macro =

Article ID: 177888

Article Last Modified on 9/12/2006

-

APPLIES TO


 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q177888



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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to 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 requirements. 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.

