How to open a jpg file using VBA?

marlonsaveri

Board Regular
Joined
Jan 28, 2011
Messages
68
Hi, I have some pictures inside pages from a multipage. I want when someone click twice, the realy image opens with windows.

Code:
Dim ListOfFiles(100) as string
(...)
Private Sub MultiPage1_DblClick(ByVal Index As Long, ByVal Cancel As MSForms.ReturnBoolean)
    
    Dim NumPag As String
    
    NumPag = MultiPage1.value
    'open file ListOfFiles(NumPage)
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
This is an indirect way to do it but it the only one I could think of.

Visit http://www.vbaexpress.com/kb/getarticle.php?kb_id=971 and copy their commandline function. That will allow you to send commands directly to Window's Command Line.

For your purposes you can just send the image file name and path as a command and the default program will open it.

Code:
Public Function CommandLine(command As String, Optional ByVal keepAlive As _
    Boolean = False, Optional windowState As VbAppWinStyle = VbAppWinStyle.vbHide) As Boolean
'''...
'''... VBAEXPRESS FUNCTION
'''...
End Function

Private Sub MultiPage1_DblClick(ByVal Index As Long, ByVal Cancel As MSForms.ReturnBoolean)
    
    Dim NumPag As String
    Dim filePath As String
    
    NumPag = MultiPage1.Value
    
    filePath = ListOfFiles(NumPage)
    
    '// Surrond string with quotation marks if file path contains any spaces
    If InStr(1, filePath, " ") Then
        filePath = """" & filePath & """"
    End If
    CommandLine filePath, False
    
End Sub

Worked for my test case. Let me know if it works out for you.
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
Members
452,915
Latest member
hannnahheileen

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