Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Run time error 1004

Hello, I am getting a run time error on the following line of my code (entire
code below). Basically I am trying to print files that are listed in the
cells. Any help is appreciated. Thanks.

*** Line erroring out***
Set bk = Workbooks.Open(cell.Name)

***Entire code***

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng

Set bk = Workbooks.Open(cell.Name)

Finalize 'print macro
bk.Close Savechanges:=False
Next


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Run time error 1004

Brad,

It looks like it should be "cell.value" or "cell.text", not "cell.name"

hth,

Doug

"Brad" wrote in message
...
Hello, I am getting a run time error on the following line of my code

(entire
code below). Basically I am trying to print files that are listed in the
cells. Any help is appreciated. Thanks.

*** Line erroring out***
Set bk = Workbooks.Open(cell.Name)

***Entire code***

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng

Set bk = Workbooks.Open(cell.Name)

Finalize 'print macro
bk.Close Savechanges:=False
Next


End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Run time error 1004

Try

Set bk = Workbooks.Open(cell.Value)

Jan


"Brad" skrev i en meddelelse
...
Hello, I am getting a run time error on the following line of my code

(entire
code below). Basically I am trying to print files that are listed in the
cells. Any help is appreciated. Thanks.

*** Line erroring out***
Set bk = Workbooks.Open(cell.Name)

***Entire code***

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng

Set bk = Workbooks.Open(cell.Name)

Finalize 'print macro
bk.Close Savechanges:=False
Next


End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Run time error 1004

If it can not open the spreadsheet then you will get this error. Here is an
easy way to handle it

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng
on error resume next
Set bk = Workbooks.Open(cell.Name)
on error goto 0

if bk is nothng then
msgbox "Sheet " & cell.Name & " could not be opened."
else
Finalize 'print macro
bk.Close Savechanges:=False
end if
Next
End Sub

otherwise very nice code...

HTH

"Brad" wrote:

Hello, I am getting a run time error on the following line of my code (entire
code below). Basically I am trying to print files that are listed in the
cells. Any help is appreciated. Thanks.

*** Line erroring out***
Set bk = Workbooks.Open(cell.Name)

***Entire code***

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng

Set bk = Workbooks.Open(cell.Name)

Finalize 'print macro
bk.Close Savechanges:=False
Next


End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Run time error 1004

I got caught nappin... Cell.value... Otherwise the code is good... :-)

"Jim Thomlinson" wrote:

If it can not open the spreadsheet then you will get this error. Here is an
easy way to handle it

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng
on error resume next
Set bk = Workbooks.Open(cell.Name)
on error goto 0

if bk is nothng then
msgbox "Sheet " & cell.Name & " could not be opened."
else
Finalize 'print macro
bk.Close Savechanges:=False
end if
Next
End Sub

otherwise very nice code...

HTH

"Brad" wrote:

Hello, I am getting a run time error on the following line of my code (entire
code below). Basically I am trying to print files that are listed in the
cells. Any help is appreciated. Thanks.

*** Line erroring out***
Set bk = Workbooks.Open(cell.Name)

***Entire code***

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng

Set bk = Workbooks.Open(cell.Name)

Finalize 'print macro
bk.Close Savechanges:=False
Next


End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Run time error 1004

Thanks all, I'll give this a try tomorrow when I'm in the office.


"Brad" wrote:

Hello, I am getting a run time error on the following line of my code (entire
code below). Basically I am trying to print files that are listed in the
cells. Any help is appreciated. Thanks.

*** Line erroring out***
Set bk = Workbooks.Open(cell.Name)

***Entire code***

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng

Set bk = Workbooks.Open(cell.Name)

Finalize 'print macro
bk.Close Savechanges:=False
Next


End Sub

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Run time error 1004

Alright, now I have changed it to (cell.value) and it saying file can not be
found. for example, in cell "A2" of the usrid sheet, it lists the entire file
name (programmed from a different module):

G:\my folder\Contract Quotes\Brad's Quotes\Renewals\test template print
queue.xls

But it is saying the file can not be found. Any ideas?

P.S. I've got to give credit to this code to Tom O, he created the whole
thing.

"Jan Kronsell" wrote:

Try

Set bk = Workbooks.Open(cell.Value)

Jan


"Brad" skrev i en meddelelse
...
Hello, I am getting a run time error on the following line of my code

(entire
code below). Basically I am trying to print files that are listed in the
cells. Any help is appreciated. Thanks.

*** Line erroring out***
Set bk = Workbooks.Open(cell.Name)

***Entire code***

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng

Set bk = Workbooks.Open(cell.Name)

Finalize 'print macro
bk.Close Savechanges:=False
Next


End Sub




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
Run time error '1004' aeddave Excel Worksheet Functions 1 January 30th 08 08:26 PM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM
Run time error '1004': Generaol ODBC error Dwaine Horton[_3_] Excel Programming 2 April 26th 05 02:52 PM
Run time error 1004 General ODCB Error Kevin Excel Programming 3 February 26th 05 12:51 PM
Application Run Time Error 1004 and Stack Error ExcelMonkey[_190_] Excel Programming 9 February 11th 05 04:48 PM


All times are GMT +1. The time now is 06:27 PM.

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"