Link to image based on info in a cell

jemcc

New Member
Joined
Nov 21, 2017
Messages
4
I have been tasked with creating measurable metrics based on entries made into our daily log, based on a nightly audit. Management has requested a screen shot of any error found prior to a correction. Since there are several employees that perform this nightly audit, I have created a simple input form for each entry, that when saved populates a separate worksheet. But, I am stuck with the images. What I envision at the moment is: The auditor will capture the appropriate info, using the snipping tool, and save it to a folder C:\Images and give it a unique name, 12345. He would then enter that name into the input form, cell "A1". When the entry is saved I want to save that file name into cell "J1" as a link to the original file C:\Images\12345.jpg. Sorry, if this is a little long winded, but I am brand new to the world of VBA.

Thanks in advance for any ideas, or suggestion that might send me down a new rabbit hole.
Jim
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try this formula in "J1" and images always in jpg format

=IF(LEN(A1)>0,HYPERLINK("file:///C:\Images" & A1 & ".jpg","C:\Images" & A1 & ".jpg"))
 
Last edited:
Upvote 0
you could put a macro to read the cell value, then open it in its own native application, be it Paint.exe or Viewer.exe.

paste this code into a module. (Developer vbe, insert , module)
Then it will open ANY file via its extension....
.pdf files will open in acrobat,
.doc files in word
etc


USAGE:
OpenNativeApp "c:\folder\file.xls"
'opens in excel
or
OpenNativeApp activecell.value
'opens item in field in native app


Code:
Option Compare Database
Option Explicit


Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&


Public Sub OpenNativeApp(ByVal psDocName As String)
Dim r As Long, msg As String


r = StartDoc(psDocName)
If r <= 32 Then
    'There was an error
    Select Case r
        Case SE_ERR_FNF
            msg = "File not found"
        Case SE_ERR_PNF
            msg = "Path not found"
        Case SE_ERR_ACCESSDENIED
            msg = "Access denied"
        Case SE_ERR_OOM
            msg = "Out of memory"
        Case SE_ERR_DLLNOTFOUND
            msg = "DLL not found"
        Case SE_ERR_SHARE
            msg = "A sharing violation occurred"
        Case SE_ERR_ASSOCINCOMPLETE
            msg = "Incomplete or invalid file association"
        Case SE_ERR_DDETIMEOUT
            msg = "DDE Time out"
        Case SE_ERR_DDEFAIL
            msg = "DDE transaction failed"
        Case SE_ERR_DDEBUSY
            msg = "DDE busy"
        Case SE_ERR_NOASSOC
            msg = "No association for file extension"
        Case ERROR_BAD_FORMAT
            msg = "Invalid EXE file or error in EXE image"
        Case Else
            msg = "Unknown error"
    End Select
'    MsgBox msg
End If
End Sub


Private Function StartDoc(psDocName As String) As Long
Dim Scr_hDC As Long


Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
End Function
 
Upvote 0
Correction..

=IF(LEN(A1)>0,HYPERLINK("file:///C:\Images" & A1 & ".jpg","C:\Images" & A1 & ".jpg"),"")
 
Upvote 0
Thank you both, for your answers. I think I can make this work now. My form has several cells for image names to be placed in, and will be copied to a separate worksheet. But, I think your solutions will put me on the proper path. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,419
Messages
6,124,796
Members
449,189
Latest member
kristinh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top