Works in module but not in project

  • Thread starter Thread starter John
  • Start date Start date
J

John

I created the following module by doing a macro record. It works by running
it within the module but when I put in a project, I get a 1004 error on the
range select. The xls file is visable while I am stepping (F8). I even did
a call statement and get the same error and change the project from Private
to Public. What am I missing?

Workbooks.Open Filename:="C:\temp\jul 07.xls"
Worksheets(2).Activate
Range("B216:Y242").Select
Selection.Copy

John
 
Dim bk as Workbook, sh as Worksheet
set bk = Workbooks.Open( Filename:="C:\temp\jul 07.xls")
set sh = bk.Worksheets(2).Activate
sh.Range("B216:Y242").Select
Selection.Copy

also, you don't need to select or activate

Dim bk as Workbook
set bk = Workbooks.Open( Filename:="C:\temp\jul 07.xls")
bk.Worksheets(2).Range("B216:Y242").Copy
 
Thank you. In ref select and activate, I was breaking it down to narrow down
where the error was.

John
 

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