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

Copper 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.

8 Replies
What does Dir(FolderName & FileName) return?

@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

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

@Jan Karel Pieterse the error is with this line

myShell.Run FolderName & FileName
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?

@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.

@Jan Karel Pieterse 

Hi Jan, Do you think my issue would be resolved if I restored factory reset my laptop? 

Dannielle

 

It might. As a workaround, you might also try this:
ActiveWorkbook.FollowHyperlink FolderName & FileName