VBA code to open a JPG file

Willand

New Member
Joined
Jan 19, 2016
Messages
2
I am working on Windows 10 and Excel 2016. I'm not an expert on VBA but normally managed to get by. However, I'm really struggling this this!

I need to open a JPG file, and view it, from a file path; which I've managed to do:

Code:
[B]
   Shell ("RunDLL32.exe C:\Windows\System32\Shimgvw.dll,ImageView_Fullscreen     C:\xxx\xxx\Documents\Images\DSCF1391.JPG")
[/B][\Code]

This works fine but I need the file path to be variable based on a Cell Value within my workbook.  I've tried the following:

[Code][B]   Dim FilePath As String[/B]
[B]   FilePath = ActiveSheet.Range("C4").Value

   Shell ("RunDLL32.exe C:\Windows\System32\Shimgvw.dll,ImageView_Fullscreen FilePath")
[/B][\Code]

It seems that the 'Shell' code doesn't recognise the 'FilePath' as a String referring back to C4?

Can anyone assist me in getting a variable file path, based on the cell value, to work in this routine?

Many thanks in advance
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I am working on Windows 10 and Excel 2016. I'm not an expert on VBA but normally managed to get by. However, I'm really struggling this this!

I need to open a JPG file, and view it, from a file path; which I've managed to do:

Code:
[B]
   Shell ("RunDLL32.exe C:\Windows\System32\Shimgvw.dll,ImageView_Fullscreen     C:\xxx\xxx\Documents\Images\DSCF1391.JPG")
[/B][\Code]

This works fine but I need the file path to be variable based on a Cell Value within my workbook.  I've tried the following:

[Code][B]   Dim FilePath As String[/B]
[B]   FilePath = ActiveSheet.Range("C4").Value

   Shell ("RunDLL32.exe C:\Windows\System32\Shimgvw.dll,ImageView_Fullscreen FilePath")
[/B][\Code]

It seems that the 'Shell' code doesn't recognise the 'FilePath' as a String referring back to C4?

Can anyone assist me in getting a variable file path, based on the cell value, to work in this routine?

Many thanks in advance[/QUOTE]
Hi Willand, welcome to the boards.

Try changing this line:

[B]Shell ("RunDLL32.exe C:\Windows\System32\Shimgvw.dll,ImageView_Fullscreen FilePath")[/B]

To this:

[B]Shell ("RunDLL32.exe C:\Windows\System32\Shimgvw.dll,ImageView_Fullscreen [COLOR=#ff0000]" & FilePath[/COLOR])


[/B]Note that the space between Fullscreen and the quotation mark are intentional
 
Last edited:
Upvote 0
This works fine but I need the file path to be variable based on a Cell Value within my workbook. I've tried the following:

Code:
[B]   Dim FilePath As String[/B]
[B]   FilePath = ActiveSheet.Range("C4").Value

   Shell ("RunDLL32.exe C:\Windows\System32\Shimgvw.dll,ImageView_Fullscreen FilePath")
[/B][\Code]

It seems that the 'Shell' code doesn't recognise the 'FilePath' as a String referring back to C4?
[/QUOTE]
Anything located between quote marks will be nothing more than a collection of characters without meaning. To make VB "see" FilePath as a variable containing text rather than simply a collection of eight characters (F, i, l, e, P, a, t and h), you must concatenate the variable name onto the quoted text...

Shell "RunDLL32.exe C:\Windows\System32\Shimgvw.dll,ImageView_Fullscreen " & FilePath

Note I removed the unnecessary parentheses (they would have been needed if you called Shell as a function, but you are calling it as a subroutine, so the parentheses are unneeded). Also note the trailing space at the end of the quoted text... that is necessary so that when the text stored in the FilePath variable is concatenated onto the quoted text, the two are separated by a single space.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,583
Members
449,174
Latest member
chandan4057

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