TPE
![]() |
![]() |
![]() |
|
|
Tavvafi@gmail.com |
|||
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
متد CommandBars.FindControl(Id:=xxx).Execute اغلب برای پیدا کردن کنترلری که ID اش xxx است بکار گرفته می شود،برای اینکار باید Ctrl+G برای نمایش Immediate window بزنید.
Sub ListAllControls()
Dim oCmdBar As CommandBar
Dim oCtrl As CommandBarControl
For Each oCmdBar In Application.CommandBars
Debug.Print oCmdBar.Name
Next
End Sub
Locate the command bar you want from the listin in the Immediate window, then use this to list all the controls on the chosen command bar. This example lists the controls on "Menu Bar", the main PowerPoint menu bar, names and IDs.
Sub ListMainMenuControls()
Dim oCmdBar As CommandBar
Dim oCtrl As CommandBarControl
Dim oCtrl2 As CommandBarControl
For Each oCmdBar In Application.CommandBars
Debug.Print oCmdBar.Name
' Substitute the name of the command bar you want here.
If oCmdBar.Name = "Menu Bar" Then
For Each oCtrl In oCmdBar.Controls
Debug.Print vbTab & oCtrl.Caption
If oCtrl.Caption = "Sli&de Show" Then
For Each oCtrl2 In oCtrl.Controls
Debug.Print vbTab & vbTab & oCtrl2.Caption & vbTab & oCtrl2.Id
Next
Exit Sub
End If
Next
End If
Next
End Sub
Note the ID of the control you want and use this to "launch" the control (ie, click it for the user, so to speak):
Sub FireAControl(lngID as Long, strErrorMessage as String)
On Error Resume Next
Call CommandBars.FindControl(Id:=lngID).Execute
If Err.Number <> 0 Then
MsgBox strErrorMessage
Err.Clear
End If
End Sub
Sub DemonstrateIt()
FireAControl 2892, "Please select something first"
End Sub



































