Solved

Presence of COMMENT causes runtime error when HYPERLINK is added to shape that is added to same xl sheet

Posted on 2015-02-22
5
52 Views
Last Modified: 2015-02-24
I DO dynamically display and delete SHAPES (derived from .jpgs) on an excel sheet.
Set Sh = ws.Shapes.AddPicture("C:\path\danger.jpg", msoCTrue, msoTrue, .Left, .Top, 20, 16)

The shapes DO actuate subs via hyperlinks;
Hyperlink ScreenTips provide users with a tooltip explanation for the informational role of each shape.

I WISH to have comments on various cells in the same xl sheet to explain other data, which is not associated with the hyperlinked shapes.

HOWEVER, as the attached demo shows (one sub of v few lines):

When I add a cell COMMENT, this causes a runtime error in the sub at the level of adding the hyperlink to the SHAPE. this occurs even when all the arguments are null:
ws.Hyperlinks.Add anchor:=ws.Shapes(ws.Shapes.Count), Address:="", SubAddress:="", ScreenTip:=""

Comments on sheet2 do not cause runtime errors to shapes added to sheet1.

This looks like a bug?
Have anyone got a work-around or other suggestion?

Thanks! Kelvin
danger.jpg
Bug-between-.addComment-to-any-cell-and-
0
Comment
Question by:Kelvin4
  • 3
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 40625210
It works fine for me in 2010, but I don't see why you don't use your Sh reference instead of ws.Shapes(ws.Shapes.Count) which may be returning the comment for you:

            '** Adjust Path details (next line) for the location of danger.jpg **
            Set Sh = ws.Shapes.AddPicture("C:\testing\bh602.png", msoCTrue, msoTrue, .Left, .Top, 20, 16)
            '''This line throws a run time error (see image of warning pasted onto Sheeet1)
            ws.Hyperlinks.Add anchor:=Sh, Address:="", SubAddress:="", ScreenTip:=""

Open in new window

0
 

Author Comment

by:Kelvin4
ID: 40628464
Thanks,
0
 

Author Closing Comment

by:Kelvin4
ID: 40628498
Rory:
Much appreciate your rapid response that I could not ack the same say.

Still a learner of the xl object model, I had thought there might be some cross-talk between the Shapes collection and the Comments collection; and thought this would be strange.  

Is such cross talk also implied within your comment that "ws.Shapes(ws.Shapes.Count) .... may be returning the comment for you:"?  

One great relief, and a SIMPLE solution!!
Thanks,
Kelvin
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 40628577
Yes, that's what I was implying. Comments (and anything else that sits in the drawing layer above a sheet) are part of the Shapes collection.
0
 

Author Comment

by:Kelvin4
ID: 40628593
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now