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
49 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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…

757 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

22 Experts available now in Live!

Get 1:1 Help Now