How to assign ToolTip for button on tool bar?

A

avkokin

Hello.
I placed button of my macro on the tool bar. When I bring mouse cursor
to this button I get ToolTip with the name of my macro. But I can't
assign own ToolTip and own icon for this button. Is it possible and
how?
Thank you very much.
 
J

Jonathan West

avkokin said:
Hello.
I placed button of my macro on the tool bar. When I bring mouse cursor
to this button I get ToolTip with the name of my macro. But I can't
assign own ToolTip and own icon for this button. Is it possible and
how?
Thank you very much.

You can't do this through the user interface. You can only do this using
VBA. Assign the string you want to the button's ToolTipText property.
 
A

avkokin

Hello Jonathan.
I should be glad to assign my own text for ToolTip but I unknow how.
That is my code for button on toolbar on left position:

Option Explicit

Dim cb As CommandBar
Dim mBtn As CommandBarButton
Dim cBtn As CommandBarButton
Dim i As Long
Dim rf As RecentFile

Sub buttonMenu()
On Error Resume Next

Set cb = CommandBars.Add("btnPopup", msoBarPopup)


For Each rf In Application.RecentFiles
If Len(Dir(rf.Path & "\" & rf.Name)) = 0 Then
Application.RecentFiles(rf.Index).Delete
End If
Next rf


For i = 1 To Application.RecentFiles.Count

Set mBtn = cb.Controls.Add(msoControlButton)
With mBtn
.Caption = Application.RecentFiles(i)
.Tag = Application.RecentFiles(i).Path & "\" &
Application.RecentFiles(i).Name
.OnAction = "openRF"
End With
Next i
With CommandBars.ActionControl
cb.ShowPopup .Left + 25, .Top + .Height - 24
End With
Set cb = Nothing
Set mBtn = Nothing
End Sub

Sub openRF()
Documents.Open CommandBars.ActionControl.Tag
End Sub
 
J

Jonathan West

avkokin said:
Hello Jonathan.
I should be glad to assign my own text for ToolTip but I unknow how.
That is my code for button on toolbar on left position:

I've added a line of code below that applies the name of the recent file to
the tooltip of the appropriate button. You can of course have the tooltip
contain something else if you prefer.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Option Explicit

Dim cb As CommandBar
Dim mBtn As CommandBarButton
Dim cBtn As CommandBarButton
Dim i As Long
Dim rf As RecentFile

Sub buttonMenu()
On Error Resume Next

Set cb = CommandBars.Add("btnPopup", msoBarPopup)


For Each rf In Application.RecentFiles
If Len(Dir(rf.Path & "\" & rf.Name)) = 0 Then
Application.RecentFiles(rf.Index).Delete
End If
Next rf


For i = 1 To Application.RecentFiles.Count

Set mBtn = cb.Controls.Add(msoControlButton)
With mBtn
.Caption = Application.RecentFiles(i)
.Tag = Application.RecentFiles(i).Path & "\" &
Application.RecentFiles(i).Name
.OnAction = "openRF"

.TooltipText = Application.RecentFiles(i).Name
 
A

avkokin

Jonathan, sorry but it not work. I need to assign ToolTip not for
items menu (anyway it not work too), and for the button of my macro.
Please see the screenshot (http://www.box.net/shared/uyipaeyz3d).
There showed ToolTip with name of the macro (buttonMenu). For this
button I need to assign the ToolTip.
But how do it for my code (above)?
Thank's.
 
J

Jonathan West

avkokin said:
Jonathan, sorry but it not work. I need to assign ToolTip not for
items menu (anyway it not work too), and for the button of my macro.
Please see the screenshot (http://www.box.net/shared/uyipaeyz3d).
There showed ToolTip with name of the macro (buttonMenu). For this
button I need to assign the ToolTip.
But how do it for my code (above)?
Thank's.

How do you identify that button? For instance, what is the name of the
toolbar it is on?
 
A

avkokin

Dear Jonathan. I found the plase whither I should insert the property
"ToolTip":

With CommandBars.ActionControl
cb.ShowPopup .Left + 25, .Top + .Height - 24
.ToolTip Text = "My own name of the button" ' !!! HERE !!!
End With

Thank you. I am sorry to trouble you.
Sincerely, Anton.
 

Ask a Question

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.

Ask a Question

Top