dellehurley
Board Regular
- Joined
- Sep 26, 2009
- Messages
- 171
- Office Version
- 365
- Platform
- Windows
Hello
I am trying to use the macros below to open files (pdf and jpg's) that are listed in a database. The file should open when double clicked on the filename which is in a listbox in userform.
It is finding the filename and folder name correctly. If the file is missing the macros correctly advises that but I cannot get it to open another document.
I think the issue is with these lines, when I watch this is what comes up.
Set myShell = CreateObject("WScript.Shell")
Watch : : WScript.Shell : <Expression not defined in context> : Empty : FrmForm.lstDatabase_DblClick
myShell.Run FolderName & FileName
Watch : : myshell.Run : <Wrong number of arguments or invalid property assignment> : Variant/Integer : FrmForm.lstDatabase_DblClick
Any help appreciated.
I am trying to use the macros below to open files (pdf and jpg's) that are listed in a database. The file should open when double clicked on the filename which is in a listbox in userform.
It is finding the filename and folder name correctly. If the file is missing the macros correctly advises that but I cannot get it to open another document.
I think the issue is with these lines, when I watch this is what comes up.
Set myShell = CreateObject("WScript.Shell")
Watch : : WScript.Shell : <Expression not defined in context> : Empty : FrmForm.lstDatabase_DblClick
myShell.Run FolderName & FileName
Watch : : myshell.Run : <Wrong number of arguments or invalid property assignment> : Variant/Integer : FrmForm.lstDatabase_DblClick
Any help appreciated.
VBA Code:
Private Sub lstDatabase_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim FolderName As String, FileName As String
Dim myShell As Object
'change folder path to database if required
FolderName = ThisWorkbook.Path & "\"
FileName = Me.lstDatabase.Value
On Error GoTo myerror
If Not Dir(FolderName & FileName, vbDirectory) = vbNullString Then
Set myShell = CreateObject("WScript.Shell")
myShell.Run FolderName & FileName
Else
Err.Raise 53
End If
'report errors
myerror:
If Err <> 0 Then MsgBox (Error(Err)), 48, "Error"
Set myShell = Nothing
End Sub