Word 2007 Quick Access Toolbar

C

Col

Hi all,

I added two buttons to the QAT to run specific macros.
I need to be able to disable one or both of them depending on the loaded
document.
I could do it with Office 2K3 and command bars but the QAT is a different
animal.

'****************2K3 code to set the enabled property of a button
Function CommandBarEnable(boolIN As Boolean, strBUTNLBL As String) As
Boolean
On Error GoTo Err_CommandBarEnable

Dim fFound As Boolean
Dim mCommandBar As CommandBar

Dim intI As Integer

fFound = False

For Each mCommandBar In CommandBars
For intI = 1 To mCommandBar.Controls.Count
If mCommandBar.Controls(intI).Caption = strBUTNLBL Then
fFound = True
mCommandBar.Controls(intI).Enabled = boolIN
Exit For
End If
Next
If fFound Then
Exit For
End If
Next
CommandBarEnable = fFound
Exit_CommandBarEnable:
Exit Function

Err_CommandBarEnable:
If Err.Number = 13 Then
Resume Next
Else
MsgBox Err.Number & " " & Err.Description, vbOKOnly + vbExclamation,
"ERROR DETECTED"
Resume Exit_CommandBarEnable
End If

End Function
'************************************************
How is this done for the buttons on the Quick Access Toolbar?

Regards
Col
 
C

Col

Just customised the QAT and selected the macros.

Patrick Schmid said:
How did you add them to the QAT?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

Hi all,

I added two buttons to the QAT to run specific macros.
I need to be able to disable one or both of them depending on the loaded
document.
I could do it with Office 2K3 and command bars but the QAT is a different
animal.

'****************2K3 code to set the enabled property of a button
Function CommandBarEnable(boolIN As Boolean, strBUTNLBL As String) As
Boolean
On Error GoTo Err_CommandBarEnable

Dim fFound As Boolean
Dim mCommandBar As CommandBar

Dim intI As Integer

fFound = False

For Each mCommandBar In CommandBars
For intI = 1 To mCommandBar.Controls.Count
If mCommandBar.Controls(intI).Caption = strBUTNLBL Then
fFound = True
mCommandBar.Controls(intI).Enabled = boolIN
Exit For
End If
Next
If fFound Then
Exit For
End If
Next
CommandBarEnable = fFound
Exit_CommandBarEnable:
Exit Function

Err_CommandBarEnable:
If Err.Number = 13 Then
Resume Next
Else
MsgBox Err.Number & " " & Err.Description, vbOKOnly +
vbExclamation,
"ERROR DETECTED"
Resume Exit_CommandBarEnable
End If

End Function
'************************************************
How is this done for the buttons on the Quick Access Toolbar?

Regards
Col
 
P

Patrick Schmid [MVP]

I can only think of one way to do this...
Write RibbonX for your code that adds the two buttons somewhere on the
Ribbon. Then you can have users add it from there to their QAT. And you
can control the enabled state via RibbonX callbacks.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

Just customised the QAT and selected the macros.

Patrick Schmid said:
How did you add them to the QAT?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

Hi all,

I added two buttons to the QAT to run specific macros.
I need to be able to disable one or both of them depending on the loaded
document.
I could do it with Office 2K3 and command bars but the QAT is a different
animal.

'****************2K3 code to set the enabled property of a button
Function CommandBarEnable(boolIN As Boolean, strBUTNLBL As String) As
Boolean
On Error GoTo Err_CommandBarEnable

Dim fFound As Boolean
Dim mCommandBar As CommandBar

Dim intI As Integer

fFound = False

For Each mCommandBar In CommandBars
For intI = 1 To mCommandBar.Controls.Count
If mCommandBar.Controls(intI).Caption = strBUTNLBL Then
fFound = True
mCommandBar.Controls(intI).Enabled = boolIN
Exit For
End If
Next
If fFound Then
Exit For
End If
Next
CommandBarEnable = fFound
Exit_CommandBarEnable:
Exit Function

Err_CommandBarEnable:
If Err.Number = 13 Then
Resume Next
Else
MsgBox Err.Number & " " & Err.Description, vbOKOnly +
vbExclamation,
"ERROR DETECTED"
Resume Exit_CommandBarEnable
End If

End Function
'************************************************
How is this done for the buttons on the Quick Access Toolbar?

Regards
Col
 
C

Col

Thanks Patrick,

Looks like I have some studying to do.

Regards
Col

Patrick Schmid said:
I can only think of one way to do this...
Write RibbonX for your code that adds the two buttons somewhere on the
Ribbon. Then you can have users add it from there to their QAT. And you
can control the enabled state via RibbonX callbacks.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

Just customised the QAT and selected the macros.

Patrick Schmid said:
How did you add them to the QAT?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed


Hi all,

I added two buttons to the QAT to run specific macros.
I need to be able to disable one or both of them depending on the
loaded
document.
I could do it with Office 2K3 and command bars but the QAT is a
different
animal.

'****************2K3 code to set the enabled property of a button
Function CommandBarEnable(boolIN As Boolean, strBUTNLBL As String) As
Boolean
On Error GoTo Err_CommandBarEnable

Dim fFound As Boolean
Dim mCommandBar As CommandBar

Dim intI As Integer

fFound = False

For Each mCommandBar In CommandBars
For intI = 1 To mCommandBar.Controls.Count
If mCommandBar.Controls(intI).Caption = strBUTNLBL Then
fFound = True
mCommandBar.Controls(intI).Enabled = boolIN
Exit For
End If
Next
If fFound Then
Exit For
End If
Next
CommandBarEnable = fFound
Exit_CommandBarEnable:
Exit Function

Err_CommandBarEnable:
If Err.Number = 13 Then
Resume Next
Else
MsgBox Err.Number & " " & Err.Description, vbOKOnly +
vbExclamation,
"ERROR DETECTED"
Resume Exit_CommandBarEnable
End If

End Function
'************************************************
How is this done for the buttons on the Quick Access Toolbar?

Regards
Col
 
P

Patrick Schmid [MVP]

Start with my blog ;)

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

Thanks Patrick,

Looks like I have some studying to do.

Regards
Col

Patrick Schmid said:
I can only think of one way to do this...
Write RibbonX for your code that adds the two buttons somewhere on the
Ribbon. Then you can have users add it from there to their QAT. And you
can control the enabled state via RibbonX callbacks.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

Just customised the QAT and selected the macros.

How did you add them to the QAT?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed


Hi all,

I added two buttons to the QAT to run specific macros.
I need to be able to disable one or both of them depending on the
loaded
document.
I could do it with Office 2K3 and command bars but the QAT is a
different
animal.

'****************2K3 code to set the enabled property of a button
Function CommandBarEnable(boolIN As Boolean, strBUTNLBL As String) As
Boolean
On Error GoTo Err_CommandBarEnable

Dim fFound As Boolean
Dim mCommandBar As CommandBar

Dim intI As Integer

fFound = False

For Each mCommandBar In CommandBars
For intI = 1 To mCommandBar.Controls.Count
If mCommandBar.Controls(intI).Caption = strBUTNLBL Then
fFound = True
mCommandBar.Controls(intI).Enabled = boolIN
Exit For
End If
Next
If fFound Then
Exit For
End If
Next
CommandBarEnable = fFound
Exit_CommandBarEnable:
Exit Function

Err_CommandBarEnable:
If Err.Number = 13 Then
Resume Next
Else
MsgBox Err.Number & " " & Err.Description, vbOKOnly +
vbExclamation,
"ERROR DETECTED"
Resume Exit_CommandBarEnable
End If

End Function
'************************************************
How is this done for the buttons on the Quick Access Toolbar?

Regards
Col
 

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