I am trying to run a shell function to open a file using Notepad.exe
I get the “invalid procedure call or argument shell” error when trying to open a file.
Sub OpenTextFile(textfile$)
Dim txtapp$, arg$
txtapp = "Notepad.exe"
textfile = "C:\Users\ADMIN\Desktop\USA - FLNG\modelout\SUMMER.CFS"
arg = Trim$(txtapp & " " & Chr$(34) & Trim$(textfile) & Chr$(34))
ierr = Shell(arg, vbNormalFocus)
End Sub
Any ideas?
This worked for me:
Type-declaration characters are considered legacy code, so I avoid them with declarations. (However I used them with Shell/Trim/Chr to avoid the Variant return type.)
I believe the error you are experiencing is because your filepath contains spaces. Try the WSHOM instead: