Private Declare Function GetAsyncKeyState Lib "user32.dll" ( _
ByVal vKey As Long) As Integer
Private Declare Function GetCursorPos Lib "user32.dll" ( _
ByRef lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Function GetRelVertical() As Currency
Dim idx As Long
Dim pCur As POINTAPI
Dim pBtnSize As POINTAPI, pBtnTL As POINTAPI
Dim RelHoriz As Currency, RelVert As Currency
If GetAsyncKeyState(vbKeyReturn) <> 0 Then
GetRelVertical = 12345 ' Enter pressed
Exit Function
End If
GetCursorPos pCur
With Application.CommandBars.ActionControl
idx = .Index
pBtnSize.x = .Width
pBtnSize.y = .Height
pBtnTL.x = .Parent.Left + 2
pBtnTL.y = .Parent.Top + 2 + (idx - 1) * (pBtnSize.y + 1)
End With
RelHoriz = (pCur.x - pBtnTL.x) / pBtnSize.x
RelVert = (pCur.y - pBtnTL.y) / pBtnSize.y
GetRelVertical = RelVert ' should be a decimal 0-1
' Debug.Print RelHoriz, RelVert
End Function
Return GetRelVertical as the first line in the macro called from the popup.
Might need to experient a bit but this seemed pretty accurate for me in both
2003/2007
Not sure if you want the relative horizontal or vertical clicked position,
both in the demo.
I assume if user selects a popup button with the keyboard and presses Enter
you need to know about it (just added that in at the last moment)
Regards,
Peter T
"minimaster" <hartmut.g...@bakerhughes.com> wrote in message
news:04b15a4d-d802-4062...@m16g2000yqc.googlegroups.com...
This value moves up and down when I move the excel window in its
position but it seems it hasn't much to do with the position of the
commandbar button.
Is this a side effect of a castrated command bar object model in Excel
2007?
If it's not a popup, explain what you mean, I don't follow what you describe
below (if not a popup). Better still post the code to create whatever it is.
Note, although popups work in Excel 2007 normal commandbars don't.
Regards,
Peter T
"minimaster" <hartmut.g...@bakerhughes.com> wrote in message
news:e62549a8-3564-4594...@m25g2000yqc.googlegroups.com...
On a commandbar I have a button - snippet from the creation of this
button:
Dim hgCmdBar As CommandBar
Dim combut As CommandBarButton
Set hgCmdBar = Application.CommandBars.Add(Name:="myPivot_Tools")
With hgCmdBar.Controls
Set combut = .Add(msoControlButton)
With combut
.Style = msoButtonIcon
.FaceID=59
.TooltipText = "Show my special custom popup menu
for PivotTable tools"
.OnAction = ShowCustomPopup
.Visible = True
.Enabled = True
End With
End With
in the procedure
Sub ShowCustomPopup()
Dim buttonTop as Long
buttonTop=Application.CommandBars.ActionControl.Top
...
End Sub
I would like to know at which screen position I can find the button
which I have on the above mentioned commandbar.
In Excel 2003 this was as simple as shown above in the code snippet
from Sub ShowCustomPopup()
As I mentioned before, in Excel 2007 custom commandbars do not exist (other
than popups), at least not in the way you intend to use them. Instead the
equivalent controls are added to the Ribbon in the Add-Ins tab.
I don't know how you'd get the position of a Ribbon control, the only
properties it appears to expose in a Call-back (control As IRibbonControl)
are Context, Id & Tag; nothing about location. Whilst not impossible I
suspect it'd be extremely difficult to work out its location.
I didn't get the original objective, something about simulating a
spinbutton - maybe time to put your own controls on the Ribbon, start here -
http://www.rondebruin.nl/ribbon.htm
Also look at Andy Pope's superb Ribbon Editor
http://www.andypope.info/vba/ribboneditor.htm
Regards,
Peter T
"minimaster" <hartmut.g...@bakerhughes.com> wrote in message
news:34f44346-51b6-497f...@p8g2000yqb.googlegroups.com...
Regards,
Peter T
"minimaster" <hartmut.g...@bakerhughes.com> wrote in message
news:252e79f6-4100-42ae...@m25g2000yqc.googlegroups.com...
Shouldn't take so long, presumably the main code will stay the same, just
the UI, unless you need to update loads of workbooks.
> My No.1 wish for Office 2010: full backward compatibility for
> commandbars as they existed in 2003.
It's not going to happen!
> My number of clicks in the Ribbon interface has gone up considerably
> since I lost my customized/optimized 2003 UI. Unfortunately I'm left
> with no real option as certain workspace functions from our comapny
> does require Excel 2010 to be installed. Frustrating!!!
Regards,
Peter T
--
Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm
"minimaster" <hartmut.g...@bakerhughes.com> wrote in message
news:252e79f6-4100-42ae...@m25g2000yqc.googlegroups.com...