Greg Greg - 5 months ago 13x
Bash Question

VBA to open a file and dll program

I have created a macro that opens a file in a predetermined program (e.g. Acrobat for pdf, Word for docs, Excel for xls). However some programs such as Windows Photo Viewer and the Zip File program are a dll file. How do I amend my code to make it work for non .exe applications?

Sub PhotoChart()

Dim strPath As String
Dim strProgram As String

strPath = "C:\Libraries\Photos\WeeklyPlanner.png"
strProgram = "C:\Program Files (x86)\Windows PhotoViewer\PhotoViewer.dll"

Call Shell("""" & strProgram & """ """ & strPath & """", vbNormalFocus)

End Sub

The Call Shell feature does not work. The computer sends back a Run-Time error '5': Invalid procedure call or argument.


try using the START command in CMD.exe instead - you shouldn't need to specify the program if the file type is already associated in the system's registry.

Shell "CMD /C START " & strPath

(no need for the Call keyword btw)

further note: If the file is not associated, it should still run but prompt you to specify a program to open the file with.