Ever had the need to specifically open an image in Windows Photo Viewer?
I’ve provided a multitude of ways to open files:
Open Files, URLs and More Using VBA and PowerShell
This is another post in my recent series of posts regarding using PowerShell to empower any VBA application. Today, I thought I’d look at how PowerShell could offer a solution to launching files. No surprise here, PowerShell easily rose to the occasion! PowerShell CmdLets I happily started out developing a function using the Invoke-Item CmdLet,…
VBA - Opening Files and URLs
So what does a developer do when he can’t sleep? He explores what options can be used to open files and/or URLs, of course! In this article I will attempt to explore multiple appraoches that can be used to open files and URLs using VBA, the choice of which one to use is left to…
but what if we don’t necessarily want to use the default application and want to specifically open the image in the Windows Photo Viewer?
Well, my first thought was to search for something like “Windows Photo Viewer Command Line Switches”, but sadly this lead nowhere.
After some digging I found 2 techniques that worked for my needs:
'---------------------------------------------------------------------------------------
' Procedure : WPV_OpenImage
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Open an image in Window Photo Viewer
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
' (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: None required
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sImg : Fully qualified path and filename of the image to open
'
' Usage:
' ~~~~~~
' WPV_OpenImage "C:\Temp\Joe.jpg"
'
' Revision History:
' Rev Date(yyyy-mm-dd) Description
' **************************************************************************************
' 1 2023-04-12
'---------------------------------------------------------------------------------------
Sub WPV_OpenImage(sImg As String)
On Error GoTo Error_Handler
Dim sProgramFilesPath As String
'sProgramFilesPath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%ProgramFiles%") '32-bit machines
sProgramFilesPath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%ProgramW6432%") '64-bit machines
Shell "RunDLL32 """ & sProgramFilesPath & "\Windows Photo Viewer\PhotoViewer.dll"", ImageView_Fullscreen " & sImg
Error_Handler_Exit:
On Error Resume Next
Exit Sub
Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Source: WPV_OpenImage" & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Sub
and/or
'---------------------------------------------------------------------------------------
' Procedure : WPV_OpenImage2
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Open an image in Window Photo Viewer
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
' (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: None required
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sImg : Fully qualified path and filename of the image to open
'
' Usage:
' ~~~~~~
' WPV_OpenImage2 "C:\Temp\Joe.jpg"
'
' Revision History:
' Rev Date(yyyy-mm-dd) Description
' **************************************************************************************
' 1 2023-04-12
'---------------------------------------------------------------------------------------
Sub WPV_OpenImage2(sImg As String)
On Error GoTo Error_Handler
Dim sWindowsPath As String
sWindowsPath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%windir%")
Shell "RunDLL32 " & sWindowsPath & "\System32\Shimgvw.dll, ImageView_Fullscreen " & sImg
Error_Handler_Exit:
On Error Resume Next
Exit Sub
Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Source: WPV_OpenImage2" & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Sub
Hi Daniel,
Is Windows Photo Viewer different from the Windows Photo app?
Someone had an issue here: https://www.utteraccess.com/topics/2064767/posts/2813094
but I suspect they are different programs.
d
I too believe they are 2 different applications.
Thanks for confirming!
David, You got me thinking, so please look at https://www.devhut.net/vba-open-image-with-ms-photos/ for one possible solution. Note, you can also use PowerShell (or PS via VBA) as well.