excelvba

Why is my workbook.open command getting a "Run-time error '1004':Application-defined or object-defined error"?


I am trying to go through a directory of .xlsx workbooks and apply processing by opening each workbook and processing it. When I try to open the first workbook I get the "Run-time error '1004': Application-defined or object-defined error". I have tried all of the variations I could find to run the Open line.

The main code for this is

Dim sFiltersFolder As String
Dim sFilterFilename As String
Dim sFilterFullFilename As String
Application.ScreenUpdating = False
sFiltersFolder = sBaseFilterSubPath
If Right(sFiltersFolder, 1) <> "\" Then sFiltersFolder = sFiltersFolder & "\"
sFilterFilename = Dir(sFiltersFolder & "*.*")
Do Until sFilterFilename = ""
    sFilterFullFilename = sFiltersFolder & sFilterFilename
    Set wbCurrentWorkbook = Workbooks.Open(sFilterFullFilename)
    Call InputMemberFile(sFilterFilename)
    Application.DisplayAlerts = False
    ThisWorkbook.Saved = False
    ThisWorkbook.Close
    sFilterFilename = Dir
Loop
Application.ScreenUpdating = True
    

I put a break on the Open line and checked all of the variables to ensure they had the expected values. Can anyone tell me what I am doing wrong?

These files are macro-free workbooks (.xlsx). they were supposed to be saved as that from a .xlsm file that helped them fill in the data. However, it turns out that several of the worksheet suppliers just changed the extension from .xlsm to .xlsx before returning it, rather than saving the file as a .xlsx file. Doing it properly fixed the problem.


Solution

  • The issue was that some of the files were not saved properly.

    These files are macro-free workbooks (.xlsx). They were supposed to be saved as such from a .xlsm file that helped them fill in the data. However, it turns out that several of the worksheet suppliers just changed the extension from .xlsm to .xlsx before returning it, rather than saving the file as a .xlsx file. Doing it properly fixed the problem.