Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Error 1004 when I open a file

Hi!

When I want to open a .xls file with VBA command:
Set bk2 = Workbooks.Open(name)

where bk2 is defined as: Dim bk2 As Workbook

I get:
'run time error '1004':
Method 'Range' of object '_Worksheet' failed

and when I look in Excel, the file is opened!

Please anybody who can help me on the right track? What is wrong?

Regards,
Mike


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Error 1004 when I open a file

Sub Tester2()
Dim wkbk As Workbook
Dim name as String
name = "C:\data\aa_userform.xls"
Set wkbk = Workbooks.Open(name)
Debug.Print wkbk.Name
End Sub

worked fine for me.

Make sure the workbook is not already open when you run the code. Probably
better not to use "name" as a variable name.

--
Regards,
Tom Ogilvy


"Deer Hunter" wrote in message
...
Hi!

When I want to open a .xls file with VBA command:
Set bk2 = Workbooks.Open(name)

where bk2 is defined as: Dim bk2 As Workbook

I get:
'run time error '1004':
Method 'Range' of object '_Worksheet' failed

and when I look in Excel, the file is opened!

Please anybody who can help me on the right track? What is wrong?

Regards,
Mike




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Error 1004 when I open a file

Hi Tom,

If I replace my code with your code, still getting the same errormessage..
Could it be something with the sheet I want to open? Protection, marco's or
something else?

Mike

"Tom Ogilvy" wrote in message
...
Sub Tester2()
Dim wkbk As Workbook
Dim name as String
name = "C:\data\aa_userform.xls"
Set wkbk = Workbooks.Open(name)
Debug.Print wkbk.Name
End Sub

worked fine for me.

Make sure the workbook is not already open when you run the code.

Probably
better not to use "name" as a variable name.

--
Regards,
Tom Ogilvy


"Deer Hunter" wrote in message
...
Hi!

When I want to open a .xls file with VBA command:
Set bk2 = Workbooks.Open(name)

where bk2 is defined as: Dim bk2 As Workbook

I get:
'run time error '1004':
Method 'Range' of object '_Worksheet' failed

and when I look in Excel, the file is opened!

Please anybody who can help me on the right track? What is wrong?

Regards,
Mike






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Error 1004 when I open a file

Well, nothing in the code you show has anything to do with a range. If that
is all the code you have, then perhaps the workbook has code it is running
which fails. If that appears to be the case, try this:

Sub Tester2()
Dim wkbk As Workbook
Dim name as String
name = "C:\data\aa_userform.xls"
Application.EnableEvents = False
Set wkbk = Workbooks.Open(name)
Application.EnableEvents = True
Debug.Print wkbk.Name
End Sub


--
Regards,
Tom Ogilvy

"Deer Hunter" wrote in message
...
Hi Tom,

If I replace my code with your code, still getting the same errormessage..
Could it be something with the sheet I want to open? Protection, marco's

or
something else?

Mike

"Tom Ogilvy" wrote in message
...
Sub Tester2()
Dim wkbk As Workbook
Dim name as String
name = "C:\data\aa_userform.xls"
Set wkbk = Workbooks.Open(name)
Debug.Print wkbk.Name
End Sub

worked fine for me.

Make sure the workbook is not already open when you run the code.

Probably
better not to use "name" as a variable name.

--
Regards,
Tom Ogilvy


"Deer Hunter" wrote in message
...
Hi!

When I want to open a .xls file with VBA command:
Set bk2 = Workbooks.Open(name)

where bk2 is defined as: Dim bk2 As Workbook

I get:
'run time error '1004':
Method 'Range' of object '_Worksheet' failed

and when I look in Excel, the file is opened!

Please anybody who can help me on the right track? What is wrong?

Regards,
Mike








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Excel file get error with file names that have spaces in the Kozmo Setting up and Configuration of Excel 6 October 29th 08 02:51 AM
EXCEL:Can't open any file without error saying it's ALREADY open??? Crackles McFarly Excel Worksheet Functions 1 November 1st 07 02:22 AM
Runtime error '1004' General ODBC error star_lucas New Users to Excel 0 August 29th 05 04:09 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
runtime error 1004 when opening excel file via VBA in a browser Ken Hunter Excel Programming 2 July 31st 03 03:33 PM


All times are GMT +1. The time now is 06:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"