Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel error code 1004 - method open of object workbooks failed

I have this code, which works perfectly in another module, but when I copied it over to module on which I'm working now, It throws

"error 1004 method open of object workbooks failed"

on the line with "Set TlWb" when I either input the file via dialog box or let the program decide for himself and I can't figure out why, because it seems so banal and there are not many options where it can go wrong. I'm pretty sure that the paths I'm providing to the program are correct and everything is DIMmed properly.

Here is the code:

'opens open prompt for ABII Parallel Import Tracker - Month/Year.xlsx, on cancel opens actual month
MsgBox "Select ABII Parallel Import Tracker - Month/Year.xlsx file to open. Cancel opens actual month"
With Application.FileDialog(msoFileDialogOpen)
    .Show
    If .SelectedItems.Count = 1 Then
        TlWbPath = .SelectedItems(1)
    End If
End With

If TlWbPath <> "" Then
   Set TlWb = Workbooks.Open(TlWbPath)

Else: Set TlWb = Workbooks.Open(traceLogPath & "ABII Parallel Import Tracker - " & Format(Date, "mmm-yyyy") & ".xlsx")
End If
like image 591
Michal Pečený Avatar asked Jun 26 '26 02:06

Michal Pečený


1 Answers

Well in the end I figured it out. The input file was corrupted, so I opened it manually and resaved it. Corruption was caused by not copying sources for dropdown list on another sheet.

like image 113
Michal Pečený Avatar answered Jun 29 '26 19:06

Michal Pečený