Run-time error '-2147024894 (80070002)' Single Macros won't work on my laptop but works for others.

%3CLINGO-SUB%20id%3D%22lingo-sub-1916515%22%20slang%3D%22en-US%22%3ERun-time%20error%20'-2147024894%20(80070002)'%20Single%20Macros%20won't%20work%20on%20my%20laptop%20but%20works%20for%20others.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1916515%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3EI%20have%20Excel%20365%20W10%20HP%20laptop.%20I%20have%20an%20excel%20file%20with%20lots%20of%20Macros%20in%20it.%20One%20single%20macros%20will%20not%20work%2C%20the%20error%20is%20%3CU%3ERun-time%20error%20'-2147024894%20(80070002)'%20Automation%20error.%20The%20system%20cannot%20find%20the%20file%20specified%3C%2FU%3E.%20The%20macros%20has%20been%26nbsp%3Btried%20by%20multiple%20people%20including%20a%20different%20laptop%20I%20own%20and%20it%20works%20perfectly.%20The%20debug%20stops%20on%20this%20line%20of%20code%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EmyShell.Run%20FolderName%20%26amp%3B%20FileName%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThe%20code%20it%20to%20double%20click%20on%20a%20listbox%20in%20a%20userform%20to%20open%20jpg%20and%20pdf%20files%20which%20are%20in%20the%20same%20folder%20as%20the%20excel%20file.%20The%20entire%20code%20for%20the%20macros%20is%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EPrivate%20Sub%20lstDatabase_DblClick(ByVal%20Cancel%20As%20MSForms.ReturnBoolean)%0A%0A%20%20%20%20Dim%20FolderName%20As%20String%2C%20FileName%20As%20String%0A%20%20%20%20Dim%20myShell%20As%20WshShell%0A%20%20%20%20%0A'change%20folder%20path%20to%20database%20if%20required%0A%20%20%20%20FolderName%20%3D%20ThisWorkbook.Path%20%26amp%3B%20%22%5C%22%0A%20%20%20%20%0A%20%20%20%20FileName%20%3D%20Me.lstDatabase.Value%0A%0A%20%20%20%20'On%20Error%20GoTo%20myerror%0A%20%20%20%20%0A%20%20%20%20If%20Not%20Dir(FolderName%20%26amp%3B%20FileName%2C%20vbNormal)%20%3D%20vbNullString%20Then%0A%20%20%20%20%20%20%20%20Set%20myShell%20%3D%20New%20WshShell%0A%20%20%20%20%20%20%20%20myShell.Run%20FolderName%20%26amp%3B%20FileName%0A%20%20%20%20Else%0A%20%20%20%20%20%20%20%20Err.Raise%2053%0A%20%20%20%20End%20If%0A%0A'report%20errors%0Amyerror%3A%0A%20%20%20%20If%20Err%20%26lt%3B%26gt%3B%200%20Then%20MsgBox%20(Error(Err))%2C%2048%2C%20%22Error%22%0A%20%20%20%20Set%20myShell%20%3D%20Nothing%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3BAny%20help%20is%20appreciated.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1916515%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1918377%22%20slang%3D%22en-US%22%3ERe%3A%20Run-time%20error%20'-2147024894%20(80070002)'%20Single%20Macros%20won't%20work%20on%20my%20laptop%20but%20works%20for%20othe%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1918377%22%20slang%3D%22en-US%22%3EWhat%20does%20Dir(FolderName%20%26amp%3B%20FileName)%20return%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1922383%22%20slang%3D%22en-US%22%3ERe%3A%20Run-time%20error%20'-2147024894%20(80070002)'%20Single%20Macros%20won't%20work%20on%20my%20laptop%20but%20works%20for%20othe%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1922383%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%26nbsp%3BHi%20Jan%2C%20I%20am%20not%20100%25%20certain%20what%20you%20mean.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20watch%20%3CFONT%20color%3D%22%23993366%22%3EFolderName%20%26amp%3B%20FileName%3C%2FFONT%3E%20I%20get%20the%20correct%20path%20to%20the%20document.%3C%2FP%3E%3CP%3Eeg.%20%3CFONT%20color%3D%22%230000FF%22%3EWatch%20%3A%20%3A%20FolderName%20%26amp%3B%20Filename%20%3A%20%22C%3A%5CUsers%5Cdelle%5CDropbox%5CGenealogy%5CFamily%20Tree%5CFMa4216.pdf%22%20%3A%20String%20%3A%20FrmForm.lstDatabase_DblClick%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20meant%20for%20me%20to%20edit%20to%20macros%20to%26nbsp%3B%3CSPAN%3E%3CFONT%20color%3D%22%23993366%22%3EDir(FolderName%20%26amp%3B%20FileName)%3C%2FFONT%3E%20it%20comes%20back%20as%20only%20the%20file%20name.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%230000FF%22%3Eeg.%20Watch%20%3A%20%3A%20Dir(FolderName%20%26amp%3B%20Filename)%20%3A%20%22FMa4216.pdf%22%20%3A%20String%20%3A%20FrmForm.lstDatabase_DblClick%3C%2FFONT%3E%3C%2FP%3E%3CP%3EIf%20I%20have%20misunderstood%20please%20let%20me%20know.%3C%2FP%3E%3CP%3ED%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1922953%22%20slang%3D%22en-US%22%3ERe%3A%20Run-time%20error%20'-2147024894%20(80070002)'%20Single%20Macros%20won't%20work%20on%20my%20laptop%20but%20works%20for%20othe%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1922953%22%20slang%3D%22en-US%22%3EOn%20which%20line%20of%20the%20code%20does%20the%20error%20occur%20precisely%3F%20(which%20line%20is%20yellow%20when%20you%20click%20Debug)%3F%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hi

I have Excel 365 W10 HP laptop. I have an excel file with lots of Macros in it. One single macros will not work, the error is Run-time error '-2147024894 (80070002)' Automation error. The system cannot find the file specified. The macros has been tried by multiple people including a different laptop I own and it works perfectly. The debug stops on this line of code 

myShell.Run FolderName & FileName

The code it to double click on a listbox in a userform to open jpg and pdf files which are in the same folder as the excel file. The entire code for the macros is 

Private Sub lstDatabase_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

    Dim FolderName As String, FileName As String
    Dim myShell As WshShell
    
'change folder path to database if required
    FolderName = ThisWorkbook.Path & "\"
    
    FileName = Me.lstDatabase.Value

    'On Error GoTo myerror
    
    If Not Dir(FolderName & FileName, vbNormal) = vbNullString Then
        Set myShell = New WshShell
        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

 Any help is appreciated.

6 Replies
Highlighted
What does Dir(FolderName & FileName) return?
Highlighted

@Jan Karel Pieterse Hi Jan, I am not 100% certain what you mean.

 

If I watch FolderName & FileName I get the correct path to the document.

eg. Watch : : FolderName & Filename : "C:\Users\delle\Dropbox\Genealogy\Family Tree\FMa4216.pdf" : String : FrmForm.lstDatabase_DblClick

 

If you meant for me to edit to macros to Dir(FolderName & FileName) it comes back as only the file name.

eg. Watch : : Dir(FolderName & Filename) : "FMa4216.pdf" : String : FrmForm.lstDatabase_DblClick

If I have misunderstood please let me know.

D

Highlighted
On which line of the code does the error occur precisely? (which line is yellow when you click Debug)?
Highlighted

@Jan Karel Pieterse the error is with this line

myShell.Run FolderName & FileName
Highlighted
Hi,

It is possible that on that particular machine there is a problem with the file association pertaining to pdf files. Rather than using the Shell command, can you create a hyperlink (for testing purposes, in an Excel cell) to the file in question and does it work? Can you open the file in question by double-clicking it in Windows explorer on the offending machine?
Highlighted

@Jan Karel Pieterse I think you are correct with the error being with my machine and shell, hopefully there is a way to fix it. If I place a hyperlink in the database and click on it (jpg or pdf) it opens perfectly. as do all the files open via file explorer too.