Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Works in module but not in project

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Works in module but not in project

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

--
Regards,
Tom Ogilvy


"John" wrote:

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Works in module but not in project

Thank you. In ref select and activate, I was breaking it down to narrow down
where the error was.

John

"Tom Ogilvy" wrote in message
...
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

--
Regards,
Tom Ogilvy


"John" wrote:

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





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
why stepping thru works differently module vs. worksheet Susan Excel Programming 5 February 13th 07 06:09 PM
when to use a module & when to use a project Sally Excel Programming 1 July 5th 06 11:30 AM
Import module in protected project? [email protected] Excel Programming 0 January 5th 05 07:38 PM
Module Names within a Project WSF Excel Programming 2 May 15th 04 11:51 PM
Remove VBA Project module TMR Excel Programming 0 December 11th 03 07:04 PM


All times are GMT +1. The time now is 02:51 PM.

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

About Us

"It's about Microsoft Excel"