PDA

View Full Version : Run-time Error '1004' - Method 'Open' of object 'Workbooks' failed



Fean
06-07-2016, 08:23 AM
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..

Paul_Hossler
06-07-2016, 08:29 AM
What's in

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

Text, formula, error, etc.?

mdmackillop
06-07-2016, 10:59 AM
Correct this

Dim WbMacro As WorkbookDim WbData As Workbook

Fean
06-08-2016, 12:15 AM
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.

Fean
06-08-2016, 12:17 AM
Correct this

Dim WbMacro As WorkbookDim WbData As Workbook

ye.. you got a point. That an copy paste error;-)

GTO
06-08-2016, 01:58 AM
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..



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))

mdmackillop
06-08-2016, 11:01 AM
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.