M
Marc Hankin
Does anyone know how to get the name of the command
button that was clicked?
thanks, marc
button that was clicked?
thanks, marc
-----Original Message-----
Ah, the buttons are in a frame. The frame will indeed come out as
ActiveControl ...
There's no Application.Caller way of retrieving system callback information
in Word.
This is an Excel feature.
Similar to VB dotnet's: 'sender As System.Object' argument to events.
Again, in Word VBA these system callbacks are not available.
You'll have explicitely pass the caller/sender as an argument to
a single routine like in below Word VBA code sequence:
code sequence/
Private Sub HandleButton(ByVal MyButton As MSForms.CommandButton)
MsgBox MyButton.Name
End Sub
Private Sub CommandButton3_Click()
HandleButton Me.CommandButton3
End Sub
Private Sub CommandButton2_Click()
HandleButton Me.CommandButton2
End Sub
/code sequence
Krgrds,
Perry
"Marc Hankin" <[email protected]> schreef in bericht
D'abord, Merci pour avoir repondu. C'est tres gentil
de votre part de donner votre temps comme ca.
Now, alas, the rest in English.
1. I tried using "CtrlName = Me.ActiveControl.Name", but
it returns the name of the frame in which the text box is
situated on the form.
2. You said: "I do not see [the] Click event for
textboxes [to which you, Marc, referred]."
I had refrained from including all the code, for fear
of bothering everyone with too much code. But, without
further ado (except to thank you for your efforts and
time), here's the entire subroutine for the text box:
Private Sub txBkMrkSplSrch01_DblClick(ByVal Cancel As
MSForms.ReturnBoolean)
'Set ActiveControl = txBkMrkSplSrch01
'txBkMrkSplSrch01.Enabled
txBkMrkSplSrch01.SetFocus
Dim strBookmark As String, strCtrlNam As String,
strCtrlNo As String, strBookmarkNam As String
Dim strTxBoxNam As String, strCtrlClkdNam As String,
CtrlName As String
Dim ctlCurrentControl As Control
Dim strControlName As String
' The next 2 lines of code are commented out,
' because the first of those 2 lines causes the
' following error message:
' "Compile error: Variable not defined", and
' the word "Screen" gets highlighted:
'
'Set ctlCurrentControl = Screen.ActiveControl
'strControlName = ctlCurrentControl.Name
'The next line is what you suggested trying.
' The msgbox returns the name of the frame in
' which the textbox is situated.
CtrlName = Me.ActiveControl.Name
MsgBox CtrlName '
'A Google search lead me to the "Application.Caller"
' approach, but I couldn't figure out how to use it.
'strCtrlNam = Application.Caller
'MsgBox strCtrlNam
strCtrlNo = Right(strCtrlNam, 1)
strBookmarkNam = "BkMrkSplSrch0" & strCtrlNo
'If the bookmark exists, delete it.
If ActiveDocument.Bookmarks.Exists("strBookmarkNam")
= True Then
ActiveDocument.Bookmarks("strBookmarkNam").Delete
End If
'Copy the selected text to this bookmark's name,
e.g., BkMrkSplSrch0?
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range,
Name:="strBookmarkNam"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
'copy the bookmarked text to a stringVar named
strBookmark
strBookmark = ActiveDocument.Bookmarks
("strBookmarkNam").Range.Text
'create a string = the name of the textbox
strTxBoxNam = "txBkMrkSplSrch0" & strCtrlNo
MsgBox strTxBoxNam
'strTxBoxNam.Text = strBookmark
End Sub
Thanks again, Marc
-----Original Message-----
Bonjour,
Dans son message, < Marc Hankin > écrivait :
In this message, < Marc Hankin > wrote:
|| Sorry for being stupid. I spent almost all day trying to
|| figure out how to use ActiveControl (or some other
|| approach) to get vba to return the name of the control
|| that was just clicked, but I can't figure it out.
As Perry mentioned, this should work:
'_______________________________________
Dim CtrlName As String
CtrlName = Me.ActiveControl.Name
'_______________________________________
|| The following lines (are triggered by the Click event
|| of a textbox):
I do not see a Click event for textboxes.
||
|| txBkMrkSplSrch01.SetFocus
|| strControlNam = frmBkMarksNavigtn.ActiveControl.Name
||
|| Instead of returning the name of the textbox that was
|| clicked, those lines return the name of the frame in
|| which the textbox is situated
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
.
.
-----Original Message-----
Bonjour,
Dans son message, < Marc Hankin > écrivait :
In this message, < Marc Hankin > wrote:
| D'abord, Merci pour avoir repondu. C'est tres gentil
| de votre part de donner votre temps comme ca.
Très bien!
| Now, alas, the rest in English.
| 1. I tried using "CtrlName = Me.ActiveControl.Name", but
| it returns the name of the frame in which the text box is
| situated on the form.
For a control in a Frame, you have to refer to the frame container, as in:
'_______________________________________
Dim CtrlName As String
CtrlName = Me.Frame1.ActiveControl.Name
'_______________________________________
| 2. You said: "I do not see [the] Click event for
| textboxes [to which you, Marc, referred]."
Ah! You posted a DoubleClick event... I was not sure If you had meant
DoubleClick for a textbox or Click for a CommandButon...
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.