?
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
Medium Priority
?
71 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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…

864 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