Help with a little code (runtime 1004)


Posted by Dan on September 18, 2001 5:51 PM

I'm trying to open a file and copy some cells with VBA, but I'm having a problem. On the Range select line I'm getting a run-time 1004 error. Any ideas what is causing this? The file is opening fine. Here is the code:
***********************
Sub datatestcopy()
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False

ChDir "C:\"
Workbooks.Open Filename:="C:\Data1.xls"

Windows("Data1.xls").Activate
Worksheets("Sheet1").Activate
Range("A1:A20").Select

End Sub
***********************

Posted by faster on September 19, 2001 8:37 AM

This code worked for me

This code worked for me. Strange. . .

Posted by Juan Pablo on September 19, 2001 9:21 AM

Re: This code worked for me

Actually, there's nothing wrong with the code, but i'm thinking that you have it assigned to a button or something, and then when you click on it, it focuses, therefor causing the error, because you cannot select a range because the button is activated... well, at least that was has happened to me a couple of times.

Juan Pablo



Posted by Dan on September 19, 2001 6:32 PM

Re: This code worked for me

Thanks guys. I figured it out with the help of another poster, Tom. I was assigning the code to an actual sheet instead of a module.