Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Just like displaying comments in excel, is it possible 2 display art? 1

Status
Not open for further replies.

YNOTU

Technical User
Jun 21, 2002
749
US
I was wondering if it's possible to display images withing excel by hovering the mouse over certain values just like when comments are inserted into a cell.

Reason I'm asking, I have this form that needs to be filled up every time a job is completed and a sample of the a label output layout must be provided to production with each form, what I do is link "View Labels here" text to the actual before production form and no problem but was wondering if displaying images was possible...


Thanks
 
Not quite in the same way comments work. . . you could use the BeforeRightClick event or SelectionChange event to display an image object to the right of a certain cell. . .

For example, if you had an image name "image1" that you wanted to appear when the user right-clicks cell B7 on sheet1, you could put this in the BeforeRightClick event of that sheet:
Code:
Dim c As Range
Set c = Application.Intersect(Target, Range("B7"))
If Not c Is Nothing Then
   Sheet1.Image1.Top = Target.Top
   Sheet1.Image1.Left = Target.Left + Target.Width
   Sheet1.Image1.Visible = True
Else
   Sheet1.Image1.Visible = False
End If
Hope that gets you pointed in the right direction!

VBAjedi [swords]
 
Thanks for the reply VBAjedi [yoda]


here's what I just did:
1. Created a new excel document and saved it to c:\test
2. pressed alt+F11 to access the VBA screen
3. double-clicked Sheet1 (Sheet1)
4. pasted your code above

5. Saved a .gif image to c:\test
5. right-clicked range B7 but nothing happened (except for the normal options when one right-clicks.



here's the code with my chagnes
*********************************
Dim c As Range
Set c = Application.Intersect(Target, Range("B7"))
If Not c Is Nothing Then
Sheet1.arrow.gif.Top = Target.Top
Sheet1.arrow.gif.Left = Target.Left + Target.Width
Sheet1.arrow.gif.Visible = True
Else
Sheet1.arrow.gif.Visible = False
End If


What am I doing wrong?
 
Ok, two things:

First, the code needs to be in the BeforeRightClick event. So either select the event from the dropdown boxes at the top of the code window, or manually add the following lines above/below the code:
Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Excel.Range, Cancel As Boolean)
  ' The code here
End Sub
Second, the image needs to be visible on the worksheet already. This approach won't go out and open an image file for you, it just references the name of an image object already on the sheet. I can't tell from your description if you have done this or not. If not, you can go to Insert > Picture > From File, select your image, and name it "arrow".

That should do it! Let me know how it goes.

VBAjedi [swords]
 
Ok, I'm obviously doing something wrong....


Here's what I did

I opened excel Insert > Picture > From File, select your image
I don't see where I should name it "arrow" as you mention. I just inserted it as below:

insert.gif



Then I pasted your sample code as follows, and get this error

insert_error.gif
 
Try right-clicking the image, then choosing "Properties". That should open the Properties pane, where you can change the name property. You might want to name it "arrow1" or something like that (in case you decide to use a different one later). Just make sure your code reflects whatever you decide to name it (for that matter, you could just change your code to refer to whatever it is currently named - which you can see in the Properties pane).

VBAjedi [swords]
 
when I right-click withing excel I get this:

right_click.gif



Anyways, thanks VBAjedi for your help and time, I'm out for the day now and will try this at a later time. Happy and safe New Year!!!!​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top