PC Review


Reply
Thread Tools Rate Thread

Applicaion.Selection on Excel

 
 
RV
Guest
Posts: n/a
 
      20th Mar 2008

Is there any other way of getting the selected range on the individual
sheets of workbook after the workbook is opened. The reason is
workbook/worksheet must be storing this last selected ranges. So whenever we
switch between the sheets the last selected ranges is shown. So from this
perspective, is there a way to get it.

With Warm Regads,

-Rahul Vakil
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      20th Mar 2008
Hi Rahul

Put this code on the codesheet for ThisWorkbook, and make sure that
CellAddress is pointing to an unused cell.

Const CellAddress As String = "A1000"
Private Sub Workbook_BeforeClose(Cancel As Boolean)
For Each sh In ThisWorkbook.Sheets
Range("A1000") = Selection.Address
Next
End Sub

Private Sub Workbook_Open()
For Each sh In ThisWorkbook.Sheets
sel = Range("A1000").Value
Range(sel).Select
Next
End Sub

Regards,

Per

"RV" <(E-Mail Removed)> skrev i meddelelsen
news:39F8431C-01A0-47DE-8842-(E-Mail Removed)...
>
> Is there any other way of getting the selected range on the individual
> sheets of workbook after the workbook is opened. The reason is
> workbook/worksheet must be storing this last selected ranges. So whenever
> we
> switch between the sheets the last selected ranges is shown. So from this
> perspective, is there a way to get it.
>
> With Warm Regads,
>
> -Rahul Vakil


 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      20th Mar 2008
A very reasonable question, as you say a non-active sheet's previous
RangeSelection must be stored somewhere (or default A1). However it is not
exposed, neither as an object nor as an address..

The RangeSelection and activecell are properties not directly of the sheet
but of a Window. A workbook always has at least one window, so FWIW you can
get the range selection of a non active wb. For the moment I'll ignore here
what occurs with if user opens multiple windows.

In passing, it's worth noting that if an embedded worksheet chart is
selected, unqualified ActiveCell will fail, would need to do
Windows(2).ActiveCell.

Somewhere hidden (invisible name-space maybe) the sheet stores certain
properties to be applied to window properties when the sheet becomes active.
When deactivated, the properties of the newly activated sheet are applied to
the Window object, RangeSelection & ActiveCell of the deactivated sheet are
no longer accessible.

Easy workaround is temporarily reactivate the sheet and get the selection.

Set newSh = Activesheet
Set ws = Workbooks("abc"),Worksheets("Sheet1")
maybe disable screen updating here
ws.parent.activate
ws.activate
set rng = Selection ' verify selection is a range
'or set rng = Windows(1).RangeSelection
' bit more here, not yet 100% sure to return a range
newSh.parent.activate
newSh.Activate

Briefly here's an outline of another workaround

- in ThisWorkbook SheetDeactivate
- verify the deactivated sheet is a worksheet, If Sh.Type = xlWorksheet then
- disable events
- trap the new activesheet, Set newSh = ActiveSheet
- reactivate the deactivated sheet, Sh.Activate
- Sh.Names.Add "LastSelection", Windows(1).RangeSelection (assumes chart not
selected)
- reactivate, newSh.Activate
- re-enable events

You can then reference the "lastSelection" from
"'sheet-Name'!LastSelection", if the name doesn't exist use default A1

Regards,
Peter T


"RV" <(E-Mail Removed)> wrote in message
news:39F8431C-01A0-47DE-8842-(E-Mail Removed)...
>
> Is there any other way of getting the selected range on the individual
> sheets of workbook after the workbook is opened. The reason is
> workbook/worksheet must be storing this last selected ranges. So whenever

we
> switch between the sheets the last selected ranges is shown. So from this
> perspective, is there a way to get it.
>
> With Warm Regads,
>
> -Rahul Vakil



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Debug .NET Applicaion =?Utf-8?B?RXJvc2hh?= Microsoft Outlook Form Programming 0 1st Oct 2007 05:09 AM
outlining applicaion the guy upstairs Freeware 26 19th Jul 2006 04:38 PM
Impersonation Windows ID in .Net Cosole applicaion bvasanth123@rediffmail.com Microsoft VB .NET 1 12th Jul 2005 11:07 PM
Applicaion error event 1000 Julian Windows XP Help 0 10th Nov 2003 09:29 PM
Re: Backup applicaion in Windows 2000 Lanwench [MVP - Exchange] Microsoft Windows 2000 0 12th Aug 2003 05:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:41 AM.