Consulting

Results 1 to 7 of 7

Thread: Run-time Error '1004' - Method 'Open' of object 'Workbooks' failed

  1. #1
    VBAX Newbie
    Joined
    Jun 2013
    Posts
    5
    Location

    Run-time Error '1004' - Method 'Open' of object 'Workbooks' failed

    Hi,

    I have an debug which i dont understand. A error Run-time Error '1004' - Method 'Open' of object 'Workbooks' failed
    On my pc its runs smoothly.. another person gets this run time error?

    Set WbData = Application.Workbooks.Open(Filename:=(FName))

    I have always used this code for opening excel files and suddenly it stops working on another pc's? Kind of very crucial to open a file..

    Any ideas?

    Dim WbMacro As WorkbookDim WbData As Workbook
    Dim FName As String
    Dim bValidBook As Boolean
    Dim supL As String
    Dim EntNr As String
    Dim StrFilename As String
    Dim Datum As String
    Dim Pass As String
    Set WbMacro = ThisWorkbook
    Dim SubTotal As String
        Application.ScreenUpdating = False
            
    Do Until Sheets("Do not delete").Cells(1, 4) = "x" 'Or bErrFound
       
          
        FName = Sheets("Macro").Cells(7, 3) 'MasterFile
        bValidBook = True
           
       Set WbData = Application.Workbooks.Open(Filename:=(FName)) 'open file '<------ HERE I GET A DEBUG
         
         WbMacro.Sheets("Do not delete").Cells(1, 4).Copy 'Entity
    
    etc..

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    What's in

    Sheets("Macro").Cells(7, 3)

    Text, formula, error, etc.?
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Correct this
    Dim WbMacro As WorkbookDim WbData As Workbook
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Newbie
    Joined
    Jun 2013
    Posts
    5
    Location
    Quote Originally Posted by Paul_Hossler View Post
    What's in

    Sheets("Macro").Cells(7, 3)

    Text, formula, error, etc.?
    C:\Datafile4.xlsm
    That is hardcoded. The user has to fill in the path/location of their datafile. This datafile will be generated for many entities.

    I might think something is wrong with the properties of this file.

  5. #5
    VBAX Newbie
    Joined
    Jun 2013
    Posts
    5
    Location
    Quote Originally Posted by mdmackillop View Post
    Correct this
    Dim WbMacro As WorkbookDim WbData As Workbook
    ye.. you got a point. That an copy paste error;-)

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by Fean View Post
    Hi,

    I have an debug which i dont understand. A error Run-time Error '1004' - Method 'Open' of object 'Workbooks' failed
    On my pc its runs smoothly.. another person gets this run time error?

    Set WbData = Application.Workbooks.Open(Filename:=(FName))

    I have always used this code for opening excel files and suddenly it stops working on another pc's? Kind of very crucial to open a file..
    Quote Originally Posted by Fean View Post
    C:\Datafile4.xlsm
    That is hardcoded. The user has to fill in the path/location of their datafile. This datafile will be generated for many entities.

    I might think something is wrong with the properties of this file.
    If the exact same file (presumably stored on a network drive) opens on one PC but not another, I would wonder what the difference is between the two. Do both have the same OS and version of Excel?

    Meanwhile, I would try ditching these parenthesis: Set WbData = Application.Workbooks.Open(Filename:= (FName))

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Modern Windows don't like you messing around on the root directory. You can't save there by code for example. Try another location to see if that is an issue.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •