Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Excel VBA Range Selection Error

Hello,

I'm using Excel and Access 2003. From within Access I open an Excel doc
with VBA, and am having trouble selecting ranges in the Excel doc. The
behavior is inconsistent in that sometimes my code works, and sometimes it
doesn't.

Code Snippet 1: Works every time

xlsWorksheet.Range("A1:A5").NumberFormat = "#,##0"

Code Snippet 2: Works sometimes, doesn't work sometimes

xlsWorksheet.Range("A1:A5").Select <--- this line fails
With xlsApp.Selection
.NumberFormat = "#,##0"
End With

The error message is: "Select method of Range class failed"

It seems accessing a range's properties directly works every time, but
selecting a range first then trying to access the selection's properties
fails during the "Select" method.

This error usually does not happen when I first open Access/Excel. But as I
start to develop, it starts happening after awhile.

The funny part is for some of the code I have recorded a macro to obtain the
code, and the maco always returns code similar to Snippet 2, the one that
fails.

Could it have to do with Excel process running in the background (I'm
setting break points and debugging and leave some processes running)?

Any ideas?

Your thoughts are appreciated!

-Scott
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Excel VBA Range Selection Error

You can not select a range until you have first selected the sheet. If the
sheet is not active then you will get the range select error. For that reason
you are best to just avoid selecting. 99% of the time the only reason you
want to select a sheet or a range is to display it to the user.
--
HTH...

Jim Thomlinson


"scottydel" wrote:

Hello,

I'm using Excel and Access 2003. From within Access I open an Excel doc
with VBA, and am having trouble selecting ranges in the Excel doc. The
behavior is inconsistent in that sometimes my code works, and sometimes it
doesn't.

Code Snippet 1: Works every time

xlsWorksheet.Range("A1:A5").NumberFormat = "#,##0"

Code Snippet 2: Works sometimes, doesn't work sometimes

xlsWorksheet.Range("A1:A5").Select <--- this line fails
With xlsApp.Selection
.NumberFormat = "#,##0"
End With

The error message is: "Select method of Range class failed"

It seems accessing a range's properties directly works every time, but
selecting a range first then trying to access the selection's properties
fails during the "Select" method.

This error usually does not happen when I first open Access/Excel. But as I
start to develop, it starts happening after awhile.

The funny part is for some of the code I have recorded a macro to obtain the
code, and the maco always returns code similar to Snippet 2, the one that
fails.

Could it have to do with Excel process running in the background (I'm
setting break points and debugging and leave some processes running)?

Any ideas?

Your thoughts are appreciated!

-Scott

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Excel VBA Range Selection Error

never done anything within access, but there is no need to select in excel, so
maybe this will work

With xlsWorksheet.Range("A1:A5")
.NumberFormat = "#,##0"
End With


--


Gary


"scottydel" wrote in message
...
Hello,

I'm using Excel and Access 2003. From within Access I open an Excel doc
with VBA, and am having trouble selecting ranges in the Excel doc. The
behavior is inconsistent in that sometimes my code works, and sometimes it
doesn't.

Code Snippet 1: Works every time

xlsWorksheet.Range("A1:A5").NumberFormat = "#,##0"

Code Snippet 2: Works sometimes, doesn't work sometimes

xlsWorksheet.Range("A1:A5").Select <--- this line fails
With xlsApp.Selection
.NumberFormat = "#,##0"
End With

The error message is: "Select method of Range class failed"

It seems accessing a range's properties directly works every time, but
selecting a range first then trying to access the selection's properties
fails during the "Select" method.

This error usually does not happen when I first open Access/Excel. But as I
start to develop, it starts happening after awhile.

The funny part is for some of the code I have recorded a macro to obtain the
code, and the maco always returns code similar to Snippet 2, the one that
fails.

Could it have to do with Excel process running in the background (I'm
setting break points and debugging and leave some processes running)?

Any ideas?

Your thoughts are appreciated!

-Scott



  #4   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Excel VBA Range Selection Error

Activate the worksheet before attempting to select the range.

xlsWorksheet.Activate
xlsWorksheet.Range("A1:A5").Select



--
Les Torchia-Wells


"scottydel" wrote:

Hello,

I'm using Excel and Access 2003. From within Access I open an Excel doc
with VBA, and am having trouble selecting ranges in the Excel doc. The
behavior is inconsistent in that sometimes my code works, and sometimes it
doesn't.

Code Snippet 1: Works every time

xlsWorksheet.Range("A1:A5").NumberFormat = "#,##0"

Code Snippet 2: Works sometimes, doesn't work sometimes

xlsWorksheet.Range("A1:A5").Select <--- this line fails
With xlsApp.Selection
.NumberFormat = "#,##0"
End With

The error message is: "Select method of Range class failed"

It seems accessing a range's properties directly works every time, but
selecting a range first then trying to access the selection's properties
fails during the "Select" method.

This error usually does not happen when I first open Access/Excel. But as I
start to develop, it starts happening after awhile.

The funny part is for some of the code I have recorded a macro to obtain the
code, and the maco always returns code similar to Snippet 2, the one that
fails.

Could it have to do with Excel process running in the background (I'm
setting break points and debugging and leave some processes running)?

Any ideas?

Your thoughts are appreciated!

-Scott

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Excel VBA Range Selection Error

Thanks for the info about selections, it's helpful. I'm going to avoid
selecting whenever possible.

FYI, I set the workseet to the workbooks's activesheet, but nowhere did I
deliberately "select" the worksheet. Any ideas why this would work
sometimes, and not work sometimes?

-Scott

"Jim Thomlinson" wrote:

You can not select a range until you have first selected the sheet. If the
sheet is not active then you will get the range select error. For that reason
you are best to just avoid selecting. 99% of the time the only reason you
want to select a sheet or a range is to display it to the user.
--
HTH...

Jim Thomlinson


"scottydel" wrote:

Hello,

I'm using Excel and Access 2003. From within Access I open an Excel doc
with VBA, and am having trouble selecting ranges in the Excel doc. The
behavior is inconsistent in that sometimes my code works, and sometimes it
doesn't.

Code Snippet 1: Works every time

xlsWorksheet.Range("A1:A5").NumberFormat = "#,##0"

Code Snippet 2: Works sometimes, doesn't work sometimes

xlsWorksheet.Range("A1:A5").Select <--- this line fails
With xlsApp.Selection
.NumberFormat = "#,##0"
End With

The error message is: "Select method of Range class failed"

It seems accessing a range's properties directly works every time, but
selecting a range first then trying to access the selection's properties
fails during the "Select" method.

This error usually does not happen when I first open Access/Excel. But as I
start to develop, it starts happening after awhile.

The funny part is for some of the code I have recorded a macro to obtain the
code, and the maco always returns code similar to Snippet 2, the one that
fails.

Could it have to do with Excel process running in the background (I'm
setting break points and debugging and leave some processes running)?

Any ideas?

Your thoughts are appreciated!

-Scott



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Excel VBA Range Selection Error

I'd need to see the code... Chances are you are changing the activesheet
somewhere...
--
HTH...

Jim Thomlinson


"scottydel" wrote:

Thanks for the info about selections, it's helpful. I'm going to avoid
selecting whenever possible.

FYI, I set the workseet to the workbooks's activesheet, but nowhere did I
deliberately "select" the worksheet. Any ideas why this would work
sometimes, and not work sometimes?

-Scott

"Jim Thomlinson" wrote:

You can not select a range until you have first selected the sheet. If the
sheet is not active then you will get the range select error. For that reason
you are best to just avoid selecting. 99% of the time the only reason you
want to select a sheet or a range is to display it to the user.
--
HTH...

Jim Thomlinson


"scottydel" wrote:

Hello,

I'm using Excel and Access 2003. From within Access I open an Excel doc
with VBA, and am having trouble selecting ranges in the Excel doc. The
behavior is inconsistent in that sometimes my code works, and sometimes it
doesn't.

Code Snippet 1: Works every time

xlsWorksheet.Range("A1:A5").NumberFormat = "#,##0"

Code Snippet 2: Works sometimes, doesn't work sometimes

xlsWorksheet.Range("A1:A5").Select <--- this line fails
With xlsApp.Selection
.NumberFormat = "#,##0"
End With

The error message is: "Select method of Range class failed"

It seems accessing a range's properties directly works every time, but
selecting a range first then trying to access the selection's properties
fails during the "Select" method.

This error usually does not happen when I first open Access/Excel. But as I
start to develop, it starts happening after awhile.

The funny part is for some of the code I have recorded a macro to obtain the
code, and the maco always returns code similar to Snippet 2, the one that
fails.

Could it have to do with Excel process running in the background (I'm
setting break points and debugging and leave some processes running)?

Any ideas?

Your thoughts are appreciated!

-Scott

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Excel VBA Range Selection Error

Any ideas why I would get the error:

"Select method of Worksheet class failed"

When I try and select a worksheet?

"Jim Thomlinson" wrote:

You can not select a range until you have first selected the sheet. If the
sheet is not active then you will get the range select error. For that reason
you are best to just avoid selecting. 99% of the time the only reason you
want to select a sheet or a range is to display it to the user.
--
HTH...

Jim Thomlinson


"scottydel" wrote:

Hello,

I'm using Excel and Access 2003. From within Access I open an Excel doc
with VBA, and am having trouble selecting ranges in the Excel doc. The
behavior is inconsistent in that sometimes my code works, and sometimes it
doesn't.

Code Snippet 1: Works every time

xlsWorksheet.Range("A1:A5").NumberFormat = "#,##0"

Code Snippet 2: Works sometimes, doesn't work sometimes

xlsWorksheet.Range("A1:A5").Select <--- this line fails
With xlsApp.Selection
.NumberFormat = "#,##0"
End With

The error message is: "Select method of Range class failed"

It seems accessing a range's properties directly works every time, but
selecting a range first then trying to access the selection's properties
fails during the "Select" method.

This error usually does not happen when I first open Access/Excel. But as I
start to develop, it starts happening after awhile.

The funny part is for some of the code I have recorded a macro to obtain the
code, and the maco always returns code similar to Snippet 2, the one that
fails.

Could it have to do with Excel process running in the background (I'm
setting break points and debugging and leave some processes running)?

Any ideas?

Your thoughts are appreciated!

-Scott

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Excel VBA Range Selection Error

To select a range the Worksheet must be the active sheet. To select a
Worksheet the Workbook must be the Active Workbook. If you can manage it you
are best off to try to avoid selecting anything. Post your code is you want
help getting rid of the select statements...
--
HTH...

Jim Thomlinson


"scottydel" wrote:

Any ideas why I would get the error:

"Select method of Worksheet class failed"

When I try and select a worksheet?

"Jim Thomlinson" wrote:

You can not select a range until you have first selected the sheet. If the
sheet is not active then you will get the range select error. For that reason
you are best to just avoid selecting. 99% of the time the only reason you
want to select a sheet or a range is to display it to the user.
--
HTH...

Jim Thomlinson


"scottydel" wrote:

Hello,

I'm using Excel and Access 2003. From within Access I open an Excel doc
with VBA, and am having trouble selecting ranges in the Excel doc. The
behavior is inconsistent in that sometimes my code works, and sometimes it
doesn't.

Code Snippet 1: Works every time

xlsWorksheet.Range("A1:A5").NumberFormat = "#,##0"

Code Snippet 2: Works sometimes, doesn't work sometimes

xlsWorksheet.Range("A1:A5").Select <--- this line fails
With xlsApp.Selection
.NumberFormat = "#,##0"
End With

The error message is: "Select method of Range class failed"

It seems accessing a range's properties directly works every time, but
selecting a range first then trying to access the selection's properties
fails during the "Select" method.

This error usually does not happen when I first open Access/Excel. But as I
start to develop, it starts happening after awhile.

The funny part is for some of the code I have recorded a macro to obtain the
code, and the maco always returns code similar to Snippet 2, the one that
fails.

Could it have to do with Excel process running in the background (I'm
setting break points and debugging and leave some processes running)?

Any ideas?

Your thoughts are appreciated!

-Scott

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
Repeatable crash in Custom Error Bar range selection Daniel Trojan[_2_] Excel Discussion (Misc queries) 2 October 28th 13 04:34 AM
Range(Selection, Selection.End(xlToRight)).Select Dave Birley Excel Programming 2 June 6th 07 04:53 PM
Excel VBA help - Range selection Harimau Excel Programming 5 February 26th 07 12:35 PM
Excel VBA - Range(Selection, Selection.End(xlDown)).Name issue. jonH Excel Programming 3 June 7th 04 09:13 PM
Strange or error : For each cl in Selection 'cl as range Jean-Yves[_2_] Excel Programming 0 March 1st 04 02:01 PM


All times are GMT +1. The time now is 03:06 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"