VBA Excel open file per click

Grz3siu

New Member
Joined
Apr 21, 2015
Messages
7
Hello, I need to open the file via VBA. After clicking on the red label, I want the file to open. I want to enter the file paths directly in the VBA code. Do you have any suggestions?

open-file.png
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I cannot see your image clearly (but I think the label caption contains the name of a TIF file)
and you have not said what is supposed to happen after "I want the file to open" (is the image supposed to go somewhere?? etc)

Perhaps...
VBA should allow user to
- view an image file
- after clicking on a label on a userform
- where the label's caption is the image file name

If so, try this
- assumes all images are in the same folder
- caption contains the file name including extension

Code goes in userform module
Code:
Private Sub [I]LabelName[/I]_Click()
    Const Fpath = "C:\Folder\subFolder[COLOR=#ff0000]\[/COLOR]"                        [I]'end string with [COLOR=#ff0000]path separator[/COLOR][/I]
    Dim fName As String
    fName = [I]LabelName[/I].Caption
    Shell ("RunDLL32.exe C:\Windows\System32\Shimgvw.dll,ImageView_Fullscreen " & Fpath & fName)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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