Re: Enable/Disable Toolbar button
- From: NZ VBA Developer <gordon(dot)bentleymix(at)gmail(dot)com>
- Date: Mon, 15 Oct 2007 03:22:01 -0700
Jay,
Thanks for the tip. I've just about got it sussed now. Here's the code I'm
using. It seems to work OK and I haven't noticed any major hit in performance.
Private Sub oApp_WindowSelectionChange(ByVal Sel As Selection)
On Error Resume Next
If Sel.Type = wdSelectionIP Then
Dim SelStyleName As String
SelStyleName = Sel.Style.NameLocal
Select Case SelStyleName
Case "Heading 1", "Heading 2", "Heading 3", "Heading 4", "List
Number", "List Number 1", "Table List Number", "Table List Number 2"
With CommandBars("Toolkit")
.Controls(6).Enabled = True
.Controls(7).Enabled = True
End With
Case Else
With CommandBars("Toolkit")
.Controls(6).Enabled = False
.Controls(7).Enabled = False
End With
End Select
End If
End Sub
My first time writing a Class Module. It's got me thinking about other
possibilities...
--
Cheers!
The Kiwi Koder
"Jay Freedman" wrote:
Yeah, I was afraid that might happen. Ratz..
There is a WindowSelectionChange event that you can monitor -- see
http://www.word.mvps.org/FAQs/MacrosVBA/ApplicationEvents.htm for the
necessary setup. If you can figure out the proper conditions to put in
an IF statement inside the event handler, you can enable/disable a
pair of custom buttons.
On Sun, 14 Oct 2007 20:31:01 -0700, NZ VBA Developer
<gordon(dot)bentleymix(at)gmail(dot)com> wrote:
Hmm... Not quite Jay...
Naming the macros as suggested does make it so they run from the 'native'
toolbar button or the right-click menu, but it still doesn't get around the
original problem. The native toolbar buttons and the right-click menu items
are still disabled when the document is protected.
What I need is a combination of the behaviour provided by the buttons for
the native functionality and the behaviour of buttons with macros assigned to
them: enabled even though the document is protected but only when the context
is correct. In fact, I'd be happy to use the native functionality rather than
my macro since all I'm trying to do is to give the users the ability to
restart/continue numbering, and the native functionality does this just fine
- just not when the doc is protected. All my macro does is change an argument
for the ApplyListTemplate method as follows:
Sub RestartNumbering()
Dim LT As ListTemplate
Set LT = Selection.Style.ListTemplate
Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=LT,
ContinuePreviousList:=False
End Sub
Sub ContinueNumbering()
Dim LT As ListTemplate
Set LT = Selection.Style.ListTemplate
Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=LT,
ContinuePreviousList:=True
End Sub
Is there a way to capture/monitor the 'selection change' event using VBA?
Seems to me that this is what Word is doing, and I've seen COM add-ins do the
same...
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
- References:
- Re: Enable/Disable Toolbar button
- From: Jay Freedman
- Re: Enable/Disable Toolbar button
- From: NZ VBA Developer
- Re: Enable/Disable Toolbar button
- From: Jay Freedman
- Re: Enable/Disable Toolbar button
- Prev by Date: Re: Help with Range.TextRetrievalMode?
- Next by Date: Re: Help with Range.TextRetrievalMode?
- Previous by thread: Re: Enable/Disable Toolbar button
- Next by thread: Re: Enable/Disable Toolbar button
- Index(es):