I'm automating PowerPoint from an application in which we control the File
open, save, saveas, close and only allow 1 file (or workbook) to be open at a
time. If the user is allowed to select anything in the Recent files list,
another workbook gets opened in the application and I'm trying to prevent
this. Here is some code I'm using to disable the Open, Save, etc., along
with the code that doesn't work for the recent files:
Private Sub CustomPptObject(objPpt As PowerPoint.Application, _
Optional BlnSaveEnabled As Boolean = True, _
Optional intResultCode As Integer = gconstOK)
'Customize the powerpoint object to be display inside the DocContainer.
On Error GoTo CustomPptObjectErr
'Dim objRecentFile As Word.RecentFile
'disable certain File menu options
With objPpt.CommandBars("Menu Bar")
.Controls("&File").Controls("&New...").Enabled = False
.Controls("&File").Controls("&Open...").Enabled = False
.Controls("&File").Controls("&Close").Enabled = False
.Controls("&File").Controls("&Exit").Enabled = False
.Controls("&File").Controls("Save &As...").Enabled = False
.Controls("&File").Controls("Save").Enabled = BlnSaveEnabled
' PowerPoint 2000 or greater
If mstrOfficeVersion = OFFICE_2000 Then
.Controls("&File").Controls("Save as Web Pa&ge...").Enabled = False
End If
End With
'disable the standard toolbar.
'"New &Blank Document"
With objPpt.CommandBars("Standard")
.Controls(1).Enabled = False
'&Open...
.Controls(2).Enabled = False
'&Save
.Controls(3).Enabled = BlnSaveEnabled
End With
'remove the recentFile list
'Search for menu items starting with "&1...", "&2...", etc.
Dim I As Integer
Dim J As Integer
Dim StartIdx As Integer
Dim EndIdx As Integer
Dim Pos As Integer
Dim CmdBarButton As Office.CommandBarButton
StartIdx = 0
EndIdx = 0
With objPpt.CommandBars("Menu Bar").Controls("&File")
For I = 1 To .Controls.Count
OutputDebugString .Controls(I).Caption
Pos = InStr(.Controls(I).Caption, "&1")
If Pos = 1 Then
'match found for first recent file
StartIdx = I
End If
Pos = InStr(.Controls(I).Caption, "&Recent")
If Pos = 1 Then
EndIdx = I
Exit For
End If
Next
On Error Resume Next
If StartIdx > 0 And EndIdx >= StartIdx Then
'Disable these menu items
For J = StartIdx To EndIdx
'TBD: None of these work!
Set CmdBarButton = .Controls(J)
CmdBarButton.Visible = False
If Err.Number <> 0 Then OutputDebugString Err.Description & vbCrLf
CmdBarButton.Enabled = False
If Err.Number <> 0 Then OutputDebugString Err.Description & vbCrLf
CmdBarButton.Delete
If Err.Number <> 0 Then OutputDebugString Err.Description & vbCrLf
Next
End If
End With
Exit Sub
CustomPptObjectErr:
On Error Resume Next
OutputDebugString "Error in CustomPptObject: " & Err.Description & vbCrLf
End Sub