ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find the name of the label within its _Click() ? (https://www.excelbanter.com/excel-programming/369933-find-name-label-within-its-_click.html)

[email protected]

Find the name of the label within its _Click() ?
 
This is one of those "there's gotta be a way" situations. I have a
UserForm with objects all over it, including a multipage form, frames
within the pages and objects, including labels, within the forms and on
the pages directly. I'd like to implement a "right click for help"
routine for all the objects including labels, since some of the labels
are designed to look and feel like hyperlinks and do perform (hopefully
useful) actions for the user. The "HelpContextID" for all objects,
including labels, has been defined.

One obvious place to start is the "MouseUp()" event and use "If Button
= 2 ...". However, from there I'm stuck. With labels, the ActiveControl
object (or in my case, the
(Me.mpgMain.SelectedItem.ActiveControl.ActiveContr ol) object is NOT the
object whose "MouseUp()" macro is being run. Rather it's the textbox
where the cursor is sitting there blinking. Does anyone know a way to
refer to the object whose MouseUp event is being called from within the
MouseUp event itself? From there I could extract the HelpContextID
property and do a 'Shell "winhlp32.exe -N ...'

Alternately does anyone know a simpler way of having a right mouse
click bring up the context-sensitive help, equivalent to how the "F1"
key works, for all types of objects oon a UserForm? It seems this used
to a standard feature in older versions of Excel/Windows but, sigh, no
longer.

= Marchand =


Jim Cone

Find the name of the label within its _Click() ?
 
Most (all) of the controls you can put on a form have a mouse up/down
event. Assign your code to each individual control.
An alternative is to add a listbox with all of the help topics and let your
users pick the one they want to read.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



wrote in message
This is one of those "there's gotta be a way" situations. I have a
UserForm with objects all over it, including a multipage form, frames
within the pages and objects, including labels, within the forms and on
the pages directly. I'd like to implement a "right click for help"
routine for all the objects including labels, since some of the labels
are designed to look and feel like hyperlinks and do perform (hopefully
useful) actions for the user. The "HelpContextID" for all objects,
including labels, has been defined.

One obvious place to start is the "MouseUp()" event and use "If Button
= 2 ...". However, from there I'm stuck. With labels, the ActiveControl
object (or in my case, the
(Me.mpgMain.SelectedItem.ActiveControl.ActiveContr ol) object is NOT the
object whose "MouseUp()" macro is being run. Rather it's the textbox
where the cursor is sitting there blinking. Does anyone know a way to
refer to the object whose MouseUp event is being called from within the
MouseUp event itself? From there I could extract the HelpContextID
property and do a 'Shell "winhlp32.exe -N ...'

Alternately does anyone know a simpler way of having a right mouse
click bring up the context-sensitive help, equivalent to how the "F1"
key works, for all types of objects oon a UserForm? It seems this used
to a standard feature in older versions of Excel/Windows but, sigh, no
longer.

= Marchand =


NickHK

Find the name of the label within its _Click() ?
 
Not exactly what you want, but text box can be made to look like labels.
Also with .Locked=true they can be edited, but can be selected, hence made
active.

NickHK

wrote in message
ups.com...
This is one of those "there's gotta be a way" situations. I have a
UserForm with objects all over it, including a multipage form, frames
within the pages and objects, including labels, within the forms and on
the pages directly. I'd like to implement a "right click for help"
routine for all the objects including labels, since some of the labels
are designed to look and feel like hyperlinks and do perform (hopefully
useful) actions for the user. The "HelpContextID" for all objects,
including labels, has been defined.

One obvious place to start is the "MouseUp()" event and use "If Button
= 2 ...". However, from there I'm stuck. With labels, the ActiveControl
object (or in my case, the
(Me.mpgMain.SelectedItem.ActiveControl.ActiveContr ol) object is NOT the
object whose "MouseUp()" macro is being run. Rather it's the textbox
where the cursor is sitting there blinking. Does anyone know a way to
refer to the object whose MouseUp event is being called from within the
MouseUp event itself? From there I could extract the HelpContextID
property and do a 'Shell "winhlp32.exe -N ...'

Alternately does anyone know a simpler way of having a right mouse
click bring up the context-sensitive help, equivalent to how the "F1"
key works, for all types of objects oon a UserForm? It seems this used
to a standard feature in older versions of Excel/Windows but, sigh, no
longer.

= Marchand =




[email protected]

Find the name of the label within its _Click() ?
 
Jim,

Thanks for your reply here. Each item already has a code assigned to
it including responding to the MouseUp event. What I'm stumbling over
is the apparent inability for the VBA code behind a label object to
identify which object it belongs to so that it can look up other
properties of itself (in this case, ContextHelpID). I'm trying to have
a single place where the ContextHelpID is stored and the property of
the label object is the obvious place to do this. I could also
hard-wire it into the VBA code, but this is error-prone and a risk for
long-term maintenance of the application.
Ths list-box idea I've also considered, but it puts a lot of burden
on the user. They would reasonably expect the computer to "know" what
they're asking help about and not have to tell it "The object I just
clicked on!". Under this approach I'd also have to create, and
maintain, a duplicate index to an help file. This is a hassle initially
and a major maintenace headache down the road as the application
evolves. Simply getting the VBA code to read other properties of the
object it belongs to would be so much simpler for design and
maintenance, as well as being easier for the user.
But then, I'm always been an optimist.


Jim Cone wrote:
Most (all) of the controls you can put on a form have a mouse up/down
event. Assign your code to each individual control.
An alternative is to add a listbox with all of the help topics and let your
users pick the one they want to read.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



wrote in message
This is one of those "there's gotta be a way" situations. I have a
UserForm with objects all over it, including a multipage form, frames
within the pages and objects, including labels, within the forms and on
the pages directly. I'd like to implement a "right click for help"
routine for all the objects including labels, since some of the labels
are designed to look and feel like hyperlinks and do perform (hopefully
useful) actions for the user. The "HelpContextID" for all objects,
including labels, has been defined.

One obvious place to start is the "MouseUp()" event and use "If Button
= 2 ...". However, from there I'm stuck. With labels, the ActiveControl
object (or in my case, the
(Me.mpgMain.SelectedItem.ActiveControl.ActiveContr ol) object is NOT the
object whose "MouseUp()" macro is being run. Rather it's the textbox
where the cursor is sitting there blinking. Does anyone know a way to
refer to the object whose MouseUp event is being called from within the
MouseUp event itself? From there I could extract the HelpContextID
property and do a 'Shell "winhlp32.exe -N ...'

Alternately does anyone know a simpler way of having a right mouse
click bring up the context-sensitive help, equivalent to how the "F1"
key works, for all types of objects oon a UserForm? It seems this used
to a standard feature in older versions of Excel/Windows but, sigh, no
longer.

= Marchand =



[email protected]

Find the name of the label within its _Click() ?
 
Nick,

You're right about this being a solution -- although it's more than
a bit of a kludge. It would really change the whole GUI design of the
application but it may be the way to go (sigh). Thanks for your
thoughts here.



NickHK wrote:
Not exactly what you want, but text box can be made to look like labels.
Also with .Locked=true they can be edited, but can be selected, hence made
active.

NickHK

wrote in message
ups.com...
This is one of those "there's gotta be a way" situations. I have a
UserForm with objects all over it, including a multipage form, frames
within the pages and objects, including labels, within the forms and on
the pages directly. I'd like to implement a "right click for help"
routine for all the objects including labels, since some of the labels
are designed to look and feel like hyperlinks and do perform (hopefully
useful) actions for the user. The "HelpContextID" for all objects,
including labels, has been defined.

One obvious place to start is the "MouseUp()" event and use "If Button
= 2 ...". However, from there I'm stuck. With labels, the ActiveControl
object (or in my case, the
(Me.mpgMain.SelectedItem.ActiveControl.ActiveContr ol) object is NOT the
object whose "MouseUp()" macro is being run. Rather it's the textbox
where the cursor is sitting there blinking. Does anyone know a way to
refer to the object whose MouseUp event is being called from within the
MouseUp event itself? From there I could extract the HelpContextID
property and do a 'Shell "winhlp32.exe -N ...'

Alternately does anyone know a simpler way of having a right mouse
click bring up the context-sensitive help, equivalent to how the "F1"
key works, for all types of objects oon a UserForm? It seems this used
to a standard feature in older versions of Excel/Windows but, sigh, no
longer.

= Marchand =



Jim Cone

Find the name of the label within its _Click() ?
 
Environment...
Label control named "SizeLabel" added to a UserForm.
SizeLabel.Tag is 10
Right clicking the label displays the contents of Range("A10") on Sheet2.
Also displayed is the name of the label...

Private Sub SizeLabel_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 Then
MsgBox Worksheets("Sheet2").Range("A1")(CLng(SizeLabel.Ta g), 1).Value
MsgBox Me.Controls("SizeLabel").Name
End If
End Sub
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html



wrote in message ups.com...
Jim,

Thanks for your reply here. Each item already has a code assigned to
it including responding to the MouseUp event. What I'm stumbling over
is the apparent inability for the VBA code behind a label object to
identify which object it belongs to so that it can look up other
properties of itself (in this case, ContextHelpID). I'm trying to have
a single place where the ContextHelpID is stored and the property of
the label object is the obvious place to do this. I could also
hard-wire it into the VBA code, but this is error-prone and a risk for
long-term maintenance of the application.
Ths list-box idea I've also considered, but it puts a lot of burden
on the user. They would reasonably expect the computer to "know" what
they're asking help about and not have to tell it "The object I just
clicked on!". Under this approach I'd also have to create, and
maintain, a duplicate index to an help file. This is a hassle initially
and a major maintenace headache down the road as the application
evolves. Simply getting the VBA code to read other properties of the
object it belongs to would be so much simpler for design and
maintenance, as well as being easier for the user.
But then, I'm always been an optimist.


Jim Cone wrote:
Most (all) of the controls you can put on a form have a mouse up/down
event. Assign your code to each individual control.
An alternative is to add a listbox with all of the help topics and let your
users pick the one they want to read.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



wrote in message
This is one of those "there's gotta be a way" situations. I have a
UserForm with objects all over it, including a multipage form, frames
within the pages and objects, including labels, within the forms and on
the pages directly. I'd like to implement a "right click for help"
routine for all the objects including labels, since some of the labels
are designed to look and feel like hyperlinks and do perform (hopefully
useful) actions for the user. The "HelpContextID" for all objects,
including labels, has been defined.

One obvious place to start is the "MouseUp()" event and use "If Button
= 2 ...". However, from there I'm stuck. With labels, the ActiveControl
object (or in my case, the
(Me.mpgMain.SelectedItem.ActiveControl.ActiveContr ol) object is NOT the
object whose "MouseUp()" macro is being run. Rather it's the textbox
where the cursor is sitting there blinking. Does anyone know a way to
refer to the object whose MouseUp event is being called from within the
MouseUp event itself? From there I could extract the HelpContextID
property and do a 'Shell "winhlp32.exe -N ...'

Alternately does anyone know a simpler way of having a right mouse
click bring up the context-sensitive help, equivalent to how the "F1"
key works, for all types of objects oon a UserForm? It seems this used
to a standard feature in older versions of Excel/Windows but, sigh, no
longer.

= Marchand =



[email protected]

Find the name of the label within its _Click() ?
 
Jim,
Good code -- thanks. It could also be revised to lookup the
ContextHelpID stored in matrix on a spreadsheet and use that # to
display a particular page within a help file. This would give users
access to the full help file contents in case they needed more than the
page in question. In another Excel application, I do this sort of thing
to give users a "right click" help on rows within a spreadsheet.
Still and all, "wouldn't it be nice" if the VBA of an object
could read the properties of its own object. Maybe in the next version
of Office...

= Marchand =


Jim Cone wrote:
Environment...
Label control named "SizeLabel" added to a UserForm.
SizeLabel.Tag is 10
Right clicking the label displays the contents of Range("A10") on Sheet2.
Also displayed is the name of the label...

Private Sub SizeLabel_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 Then
MsgBox Worksheets("Sheet2").Range("A1")(CLng(SizeLabel.Ta g), 1).Value
MsgBox Me.Controls("SizeLabel").Name
End If
End Sub
--
Jim Cone
San Francisco, USA
http://www.officeletter.com/blink/specialsort.html



wrote in message ups.com...
Jim,

Thanks for your reply here. Each item already has a code assigned to
it including responding to the MouseUp event. What I'm stumbling over
is the apparent inability for the VBA code behind a label object to
identify which object it belongs to so that it can look up other
properties of itself (in this case, ContextHelpID). I'm trying to have
a single place where the ContextHelpID is stored and the property of
the label object is the obvious place to do this. I could also
hard-wire it into the VBA code, but this is error-prone and a risk for
long-term maintenance of the application.
Ths list-box idea I've also considered, but it puts a lot of burden
on the user. They would reasonably expect the computer to "know" what
they're asking help about and not have to tell it "The object I just
clicked on!". Under this approach I'd also have to create, and
maintain, a duplicate index to an help file. This is a hassle initially
and a major maintenace headache down the road as the application
evolves. Simply getting the VBA code to read other properties of the
object it belongs to would be so much simpler for design and
maintenance, as well as being easier for the user.
But then, I'm always been an optimist.


Jim Cone wrote:
Most (all) of the controls you can put on a form have a mouse up/down
event. Assign your code to each individual control.
An alternative is to add a listbox with all of the help topics and let your
users pick the one they want to read.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



wrote in message
This is one of those "there's gotta be a way" situations. I have a
UserForm with objects all over it, including a multipage form, frames
within the pages and objects, including labels, within the forms and on
the pages directly. I'd like to implement a "right click for help"
routine for all the objects including labels, since some of the labels
are designed to look and feel like hyperlinks and do perform (hopefully
useful) actions for the user. The "HelpContextID" for all objects,
including labels, has been defined.

One obvious place to start is the "MouseUp()" event and use "If Button
= 2 ...". However, from there I'm stuck. With labels, the ActiveControl
object (or in my case, the
(Me.mpgMain.SelectedItem.ActiveControl.ActiveContr ol) object is NOT the
object whose "MouseUp()" macro is being run. Rather it's the textbox
where the cursor is sitting there blinking. Does anyone know a way to
refer to the object whose MouseUp event is being called from within the
MouseUp event itself? From there I could extract the HelpContextID
property and do a 'Shell "winhlp32.exe -N ...'

Alternately does anyone know a simpler way of having a right mouse
click bring up the context-sensitive help, equivalent to how the "F1"
key works, for all types of objects oon a UserForm? It seems this used
to a standard feature in older versions of Excel/Windows but, sigh, no
longer.

= Marchand =




All times are GMT +1. The time now is 07:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com