Displaying picture NOT EMBEDDED from Excel VBA

70 Views Asked by At

The following command works in a command prompt:

%SystemRoot%\System32\rundll32.exe "C:\Program Files\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen C:\Test.jpg

In Excel VBA, I have tried several things. The first example below gets 53 File not found. The second example appears to run but nothing is displayed.

    Sub ViewPhoto()

        Dim strExe As String
        strExe = """%SystemRoot%\System32\rundll32.exe ""%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll"", ImageView_Fullscreen c:\test.jpg"""
        MsgBox strExe
        'VBA.Shell strExe

        strExe = """C:\Windows\System32\rundll32.exe ""%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll"", ImageView_Fullscreen c:\test.jpg"""
        MsgBox strExe
        VBA.Shell strExe

    End Sub

I DO NOT want to embed the photos in Excel. They are updated frequently.

The following successfully opens PhotoViewer:

    VBA.Shell "C:\Windows\System32\rundll32.exe ""C:\Program Files\Windows Photo Viewer\PhotoViewer.dll"", ImageView_Fullscreen"
1

There are 1 best solutions below

0
Derek Johnson On

I finally figured it out. The full path to the photo is in the ActiveCell, enclosed in quotes.

    Sub ViewPhoto()
        VBA.Shell "C:\Windows\System32\rundll32.exe ""C:\Program Files\Windows Photo Viewer\PhotoViewer.dll"", ImageView_Fullscreen " & ActiveCell.Value
    End Sub