Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Error in code

I have the following code for Excel 2003:

Private Sub btnPrint1_Click()

Sheets("CapeCod").Select
ActiveSheet.Unprotect
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.Visible = False
Windows("FinancialProjections.xls").Activate


' It errors out on this statement
Range("B2").Select


ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("COSTS").Select

End Sub

I created this code through recording a macro. It is run from a button. Any
ideas on what could be stopping it? The exact error message is....

Run time error 1004
Select method of range class failed.
--
M. Shipp
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Error in code

Just a question. Was FinancialProjections.xls openned before you attempted
to activate it?
--
Gary's Student


"SHIPP" wrote:

I have the following code for Excel 2003:

Private Sub btnPrint1_Click()

Sheets("CapeCod").Select
ActiveSheet.Unprotect
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.Visible = False
Windows("FinancialProjections.xls").Activate


' It errors out on this statement
Range("B2").Select


ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("COSTS").Select

End Sub

I created this code through recording a macro. It is run from a button. Any
ideas on what could be stopping it? The exact error message is....

Run time error 1004
Select method of range class failed.
--
M. Shipp

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Error in code

Yes, it was open.
--
M. Shipp


"Gary''s Student" wrote:

Just a question. Was FinancialProjections.xls openned before you attempted
to activate it?
--
Gary's Student


"SHIPP" wrote:

I have the following code for Excel 2003:

Private Sub btnPrint1_Click()

Sheets("CapeCod").Select
ActiveSheet.Unprotect
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.Visible = False
Windows("FinancialProjections.xls").Activate


' It errors out on this statement
Range("B2").Select


ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("COSTS").Select

End Sub

I created this code through recording a macro. It is run from a button. Any
ideas on what could be stopping it? The exact error message is....

Run time error 1004
Select method of range class failed.
--
M. Shipp

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Error in code

When you have code in the worksheet module, then unqualified ranges will refer
to the worksheet that owns the code.

So you're trying to select B2 of that sheet with the button on it. But since
you're in a different workbook (maybe???) in a different worksheet (maybe???),
your code blows up. (You can only select a range if that sheet is active.)

I don't see why you really want to select B2, but you could try:

Activesheet.range("b2").select



SHIPP wrote:

I have the following code for Excel 2003:

Private Sub btnPrint1_Click()

Sheets("CapeCod").Select
ActiveSheet.Unprotect
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveWindow.Visible = False
Windows("FinancialProjections.xls").Activate

' It errors out on this statement
Range("B2").Select

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("COSTS").Select

End Sub

I created this code through recording a macro. It is run from a button. Any
ideas on what could be stopping it? The exact error message is....

Run time error 1004
Select method of range class failed.
--
M. Shipp


--

Dave Peterson
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
error with code terilad Excel Discussion (Misc queries) 4 April 12th 10 06:20 PM
Help with error code Tempy Excel Programming 1 September 28th 05 03:17 PM
Error Code 6 Dave Excel Programming 5 September 7th 05 07:12 PM
How can I still go to the error-code after a On Error Goto? Michel[_3_] Excel Programming 2 May 4th 04 04:21 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


All times are GMT +1. The time now is 06:22 AM.

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"