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
62 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

705 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