Application-defined or object-defined error

  • Thread starter Thread starter Glenn Mulno
  • Start date Start date
G

Glenn Mulno

Hi,

I find myself stumped by an incredibly easy piece of code and one that I
have used before.

I am getting the error:
Run-time error '1004':
Application-defined or object-defined error

I am getting the error when I run the following code:

Private Sub Workbook_Open()

With Application
.ScreenUpdating = False
.DisplayAlerts = False

Workbooks.Open
"\\depot02\rel\www\internal\business_areas\edg\Metrics\Phones\HighHoldTimesDetailed.xls"
Workbooks("HighHoldTimesDetailed.xls").Worksheets("data").Cells.Copy _
Workbooks("phoneholdtimes.xls").Worksheets("data").Cells
'error happens on above line(multi line)

Workbooks("HighHoldTimesDetailed.xls").Close False
.ScreenUpdating = True
.DisplayAlerts = True
.ActiveWorkbook.Saved = True
End With

'Worksheets("data").Activate
Worksheets("Team Graphs - Combined").Activate

End Sub

This runs when the file opens. The point of it is to copy a worksheet from
one file into the current file.

It opens the source file ok but chokes on the actual copy command. I do not
understand why. I have used the above lines of code many many times in many
files to copy worksheets from one workbook to another and have never had a
problem before.

The only difference than before is the location of the source file, normally
when I run this set of commands the source and destination files are in the
same directory. But the code opened the source file ok, so I do not think it
is that.

Also - I know the source file has a lot of data on the worksheet "data".

Is there something obvious I messed up here? Some blatant typo?

Thanks in advance for another set of eyes!
 
Glenn

I'd guess that you need to tell Excel where the destination file is
stored, otherwise it'll be looking in the same directory as the source.

Cheers

Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top