PC Review


Reply
Thread Tools Rate Thread

Defining location of sheet relative to the screen.

 
 
=?Utf-8?B?QmlsbCBOZXZpbg==?=
Guest
Posts: n/a
 
      30th Jul 2007
Hi, I've been attempting to create a macro for a shape that covers a region.
The macro is designed so that where ever you click on the shape, it will find
which cell your mouse is over on and highlight that cell accordingly. I've
managed to factor in different variables like application position, worksheet
position, scrollbar, etc... however there is one variable I cannot figure out
how to aquire and that is the position of the sheet itself relative to the
window. That is to say, how do I define how much space the end user is using
for toolbars. Right now this is just a constant which is obviously a problem
if the end-users don't have the same toolbar setup that I use. I know that
there are tons of objects that define a "top" method in them, but I've tried
several and none of them are useful to me. I've also tried cycling through
the CommandBar objects to get their heights but that's not working right. So
does anyone know which property I could use to get the height I need so that
I can factor it into the algorithm?

------------------------------------------------------------------------

Sub GridArea_Click()
Dim CursPos As POINTAPI
Dim locRow As String
Dim locCol As String
Dim ScrollXPos As Integer
Dim ScrollYPos As Integer
Dim AppXPos As Integer
Dim AppYPos As Integer

Call GetCursorPos(CursPos)

ScrollXPos = (Windows(1).ScrollColumn - 1) * Range("C1").Width
ScrollYPos = (Windows(1).ScrollRow - 1) * Range("C1").Height

AppXPos = IIf(Application.WindowState = xlMaximized, 2, Application.Left)
AppYPos = IIf(Application.WindowState = xlMaximized, 3, Application.Top)

locRow = Chr(((CursPos.x - 323 + ScrollXPos - AppXPos) \ 29) + 67)
locCol = CStr(((CursPos.y - 172 + ScrollYPos - AppYPos) \ 17) + 3)
' By the way, this converts the numbers to a range (ie "A1"), however, I
' do believe there must be a way to reference range by number index. No?

If Range(locRow & locCol).Interior.ColorIndex = 3 Then
Range(locRow & locCol).Interior.ColorIndex = 41
Range(locRow & locCol).Value = Range(locRow & "2").Value
ElseIf Range(locRow & locCol).Interior.ColorIndex = 41 Then
Range(locRow & locCol).Interior.ColorIndex = 15
Range(locRow & locCol).Interior.Pattern = xlGray25
Range(locRow & locCol).ClearContents
If (Range(Chr(Asc(locRow) - 1) & locCol).Interior.ColorIndex = 15) Then
Range(locRow & locCol).Borders(xlEdgeLeft).LineStyle = xlNone
End If
If (Range(Chr(Asc(locRow) + 1) & locCol).Interior.ColorIndex = 15) Then
Range(locRow & locCol).Borders(xlEdgeRight).LineStyle = xlNone
End If
ElseIf Range(locRow & locCol).Interior.ColorIndex = 15 Then
Range(locRow & locCol).Interior.ColorIndex = 0
Range(locRow & locCol).Interior.Pattern = xlNone
Range(locRow & locCol).Value = Range(locRow & "2").Value
Range(locRow & locCol).Borders(xlEdgeLeft).LineStyle = xlThin
Range(locRow & locCol).Borders(xlEdgeLeft).ColorIndex = 2
Range(locRow & locCol).Borders(xlEdgeRight).LineStyle = xlThin
Range(locRow & locCol).Borders(xlEdgeRight).ColorIndex = 2
Else
Range(locRow & locCol).Interior.ColorIndex = 3
Range(locRow & locCol).Value = Range(locRow & "2").Value
End If

' MsgBox CursPos.x & " " & CursPos.y & " " & locRow & " " & locCol
End Sub

 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      31st Jul 2007
Bill,
Maybe see how Chip calculates position in
http://www.cpearson.com/excel/FormPosition.htm

NickHK

"Bill Nevin" <(E-Mail Removed)> wrote in message
news:C07798EE-B955-4BA8-98C6-(E-Mail Removed)...
> Hi, I've been attempting to create a macro for a shape that covers a

region.
> The macro is designed so that where ever you click on the shape, it will

find
> which cell your mouse is over on and highlight that cell accordingly. I've
> managed to factor in different variables like application position,

worksheet
> position, scrollbar, etc... however there is one variable I cannot figure

out
> how to aquire and that is the position of the sheet itself relative to the
> window. That is to say, how do I define how much space the end user is

using
> for toolbars. Right now this is just a constant which is obviously a

problem
> if the end-users don't have the same toolbar setup that I use. I know that
> there are tons of objects that define a "top" method in them, but I've

tried
> several and none of them are useful to me. I've also tried cycling through
> the CommandBar objects to get their heights but that's not working right.

So
> does anyone know which property I could use to get the height I need so

that
> I can factor it into the algorithm?
>
> ------------------------------------------------------------------------
>
> Sub GridArea_Click()
> Dim CursPos As POINTAPI
> Dim locRow As String
> Dim locCol As String
> Dim ScrollXPos As Integer
> Dim ScrollYPos As Integer
> Dim AppXPos As Integer
> Dim AppYPos As Integer
>
> Call GetCursorPos(CursPos)
>
> ScrollXPos = (Windows(1).ScrollColumn - 1) * Range("C1").Width
> ScrollYPos = (Windows(1).ScrollRow - 1) * Range("C1").Height
>
> AppXPos = IIf(Application.WindowState = xlMaximized, 2,

Application.Left)
> AppYPos = IIf(Application.WindowState = xlMaximized, 3, Application.Top)
>
> locRow = Chr(((CursPos.x - 323 + ScrollXPos - AppXPos) \ 29) + 67)
> locCol = CStr(((CursPos.y - 172 + ScrollYPos - AppYPos) \ 17) + 3)
> ' By the way, this converts the numbers to a range (ie "A1"), however, I
> ' do believe there must be a way to reference range by number index. No?
>
> If Range(locRow & locCol).Interior.ColorIndex = 3 Then
> Range(locRow & locCol).Interior.ColorIndex = 41
> Range(locRow & locCol).Value = Range(locRow & "2").Value
> ElseIf Range(locRow & locCol).Interior.ColorIndex = 41 Then
> Range(locRow & locCol).Interior.ColorIndex = 15
> Range(locRow & locCol).Interior.Pattern = xlGray25
> Range(locRow & locCol).ClearContents
> If (Range(Chr(Asc(locRow) - 1) & locCol).Interior.ColorIndex = 15)

Then
> Range(locRow & locCol).Borders(xlEdgeLeft).LineStyle = xlNone
> End If
> If (Range(Chr(Asc(locRow) + 1) & locCol).Interior.ColorIndex = 15)

Then
> Range(locRow & locCol).Borders(xlEdgeRight).LineStyle = xlNone
> End If
> ElseIf Range(locRow & locCol).Interior.ColorIndex = 15 Then
> Range(locRow & locCol).Interior.ColorIndex = 0
> Range(locRow & locCol).Interior.Pattern = xlNone
> Range(locRow & locCol).Value = Range(locRow & "2").Value
> Range(locRow & locCol).Borders(xlEdgeLeft).LineStyle = xlThin
> Range(locRow & locCol).Borders(xlEdgeLeft).ColorIndex = 2
> Range(locRow & locCol).Borders(xlEdgeRight).LineStyle = xlThin
> Range(locRow & locCol).Borders(xlEdgeRight).ColorIndex = 2
> Else
> Range(locRow & locCol).Interior.ColorIndex = 3
> Range(locRow & locCol).Value = Range(locRow & "2").Value
> End If
>
> ' MsgBox CursPos.x & " " & CursPos.y & " " & locRow & " " &

locCol
> End Sub
>



 
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
Defining Location of IMAP PST FIle srm Microsoft Outlook 6 14th Apr 2009 03:20 PM
Work sheet size relative to screen size =?Utf-8?B?RmxvcmlkYSBUb20=?= Microsoft Excel Misc 1 16th Apr 2007 02:22 AM
Defining Range with Relative R[1]C[1] notation aca Microsoft Excel Programming 6 29th May 2006 08:44 AM
Defining input file location =?Utf-8?B?Qm9i?= Microsoft Access External Data 10 6th Apr 2006 07:59 PM
relative sheet references ala sheet(-1)!B11 so I can copy a sheet. =?Utf-8?B?Um9uTWM1?= Microsoft Excel Misc 9 3rd Feb 2005 12:51 AM


Features
 

Advertising
 

Newsgroups
 


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