Solved

Automating addition of shortcut icons to excel worksheet cells

Posted on 2014-10-30
5
524 Views
Last Modified: 2014-11-09
My excel worksheet contains a column of file addresses
I want to use AUTOMATION to add a graphic short cut to each row, so when I click a shortcut, it opens the file addressed on that row.

I did a manual trial, and recorded the macro below.  It causes a shortcut (MyFilename.png) to be positioned within cell B7, and to gain a hyperlink which opens file: 'Support.log".

My MAIN QUESTION: This worksheet will end up as a large catalogue of files. I need to search for files against names or tags, and import and export file details; further - this list of utilities is likely to increase..
Given that requirement, is my intention of using shortcut icons the right way to go about building a directory of links to files? OR: are there better solutions?
 
My subsidiary QUESTION, is about computing  .ScaleWidth and .ScaleHeight, please see below.

Thanks! Kelvin4

Sub Macro2()
    Range("D7").Select
    ActiveSheet.Pictures.Insert("Path\MyFileName.png").Select
    Selection.ShapeRange.ScaleWidth 0.4923809159, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleHeight 0.4923809159, msoFalse, msoScaleFromTopLeft
    ActiveSheet.Hyperlinks.Add Anchor:=Selection.ShapeRange.Item(1), Address:= "Support.log"
End Sub

.ScaleWidth and .ScaleHeight needed to be changed to 0.7 for graphic MyFileName.png to fill the height of the Excel cell. Can VBA calculate the required values of .ScaleWidth and .ScaleHeight?

I locked the sheet:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
and Unlocked:
ActiveSheet.Unprotect
0
Comment
Question by:Kelvin4
  • 3
  • 2
5 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40418521
This will place the graphic over the cell and make the graphic's dimensions the same as that of the cell. I commented out the hyperlink to make it easier for me.

Sub Macro2()
    With Range("D7")
        ActiveSheet.Shapes.AddPicture "Path\MyFileName.png", msoCTrue, msoTrue, .Left, .Top, .Width, .Height
        'ActiveSheet.Hyperlinks.Add Anchor:=Selection.ShapeRange.Item(1), Address:="Support.log"
    End With
End Sub

Open in new window

0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40418604
And if you want it to be the same height as the cell but maintain the aspect ratio then do this

Sub Macro2()
   
    With Range("D7")
        ActiveSheet.Shapes.AddPicture "Path\MyFileName.png", msoCTrue, msoTrue, .Left, .Top, -1, -1
        ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Height = .Height
        'ActiveSheet.Hyperlinks.Add Anchor:=Selection.ShapeRange.Item(1), Address:="Support.log"
    End With
    
End Sub

Open in new window

0
 

Author Comment

by:Kelvin4
ID: 40419824
Thanks Martin, am tied up presently, but should test the script tomorrow.
I get back promptly,
Kelvin.
0
 

Author Closing Comment

by:Kelvin4
ID: 40431589
Thank you for helping me so promptly.
I apologise for my late acknowledgement due to an unrelated issue.

Once I was able to test it, I got the code to work immediately, and the graphic looks great.

Kelvin
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40431597
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Office 2016 User Guides 5 33
VS2015 Redefinition errors 4 29
In search of x17-22375.exe 2 13
remove lower case characters in excel formula 12 39
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

920 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

12 Experts available now in Live!

Get 1:1 Help Now