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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
NEED LOOK FOR NUM 23 28
Excel VBA Script 9 55
LOOK FOR 22 27
Excel Index/Match issue 4 12
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

739 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