※ この情報はOffice 2010 Public Beta版を元にしています。製品版では変更になる可能性がありますのでご注意ください。
今回はファイルタブボタンのクリックを禁止する方法を紹介します。
1. Officeファイルを開きます(今回はExcelファイル)。
2. 標準モジュールに下記コードを貼り付けて上書き保存した後、ファイルを閉じます。
Option Explicit
Private Declare Function AccessibleChildren Lib "oleacc" (ByVal paccContainer As Office.IAccessible, ByVal iChildStart As Long, ByVal cChildren As Long, ByRef rgvarChildren As Any, ByRef pcObtained As Long) As Long
Private Const CHILDID_SELF = 0&
Private Const ROLE_SYSTEM_PUSHBUTTON = &H2B
Sub backstage_onShow(contextObject As Object)
Dim acc As Office.IAccessible
Set acc = Application.CommandBars("Ribbon")
Set acc = GetAcc(acc, "ファイル タブ", ROLE_SYSTEM_PUSHBUTTON)
If acc Is Nothing Then Exit Sub
If acc.accState(CHILDID_SELF) = &H300008 Then
MsgBox "ファイルタブボタンのクリック禁止", vbCritical
Call acc.accDoDefaultAction(CHILDID_SELF)
End If
End Sub
Private Function GetAcc(myAcc As Office.IAccessible, myAccName As String, myAccRole As Long) As Office.IAccessible
Dim ReturnAcc As Office.IAccessible
Dim ChildAcc As Office.IAccessible
Dim List() As Variant
Dim Count As Long
Dim i As Long
If (myAcc.accState(CHILDID_SELF) <> 32769) And _
(myAcc.accName(CHILDID_SELF) = myAccName) And _
(myAcc.accRole(CHILDID_SELF) = myAccRole) Then
Set ReturnAcc = myAcc
Else
Count = myAcc.accChildCount
If Count > 0& Then
ReDim List(Count - 1&)
If AccessibleChildren(myAcc, 0&, ByVal Count, List(0), Count) = 0& Then
For i = LBound(List) To UBound(List)
If TypeOf List(i) Is Office.IAccessible Then
Set ChildAcc = List(i)
Set ReturnAcc = GetAcc(ChildAcc, myAccName, myAccRole)
If Not ReturnAcc Is Nothing Then Exit For
End If
Next
End If
End If
End If
Set GetAcc = ReturnAcc
End Function
<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<backstage onShow="backstage_onShow" />
</customUI>