• error 1004 when opening workboek (XL 2003)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » error 1004 when opening workboek (XL 2003)

    Author
    Topic
    #450414

    Hello all,

    I’m running a macro that is opening different Workbooks.
    A lot of workbooks are corretly opened, but on some workbooks I get the following message:
    “error 1004 Run-time error ‘1004’: method ‘Open’ of object ‘Workbooks’ failed”

    The VBA code I use is:
    Workbooks.Open Filename:=txtPadDB & “tblDBCs” & CStr(lngACT) & “.xls”, ReadOnly:=True

    the strange thing is that if I choose the go to the code and the VBA editor opens, I just pres the [> continue button the code runs without a problem.
    It opens some workbook, en suddenly is stops again with the same error, but again after presing [Continue] it runs that line with out an error.

    What could be the problem here?
    Thanks in advance for your reactions.

    Viewing 0 reply threads
    Author
    Replies
    • #1106436

      Perhaps you’re opening the workbooks too quickly – try inserting one or more lines

      DoEvents

      in the code. If that doesn’t help, you may have to create a delay by using Application.OnTime.

      • #1106447

        Hans,

        Thanks for the suggestion.
        The DoEvents did not solve the problem
        I used te following: Application.Wait (Now + TimeValue(“0:00:01”))

    Viewing 0 reply threads
    Reply To: error 1004 when opening workboek (XL 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: