T
Tyron
I need to make the ebutton, when it auto opens as a toolbar that it
automatically executes without clicking it
Regards
Tyronne
Sub Auto_Open()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim cButton As CommandBarButton
Dim dButton As CommandBarButton
Dim eButton As CommandBarButton
Dim MyToolbar As String
' Give the toolbar a name
MyToolbar = "Kaupthing Palette"
On Error Resume Next ' so that it doesn't stop on the next line
if the toolbar's already there
' Create the toolbar; PowerPoint will error if it already exists
Set oToolbar = CommandBars.Add(Name:=MyToolbar,
Position:=msoBarFloating, Temporary:=True)
If Err.Number <> 0 Then ' The toolbar's already there, so we have
nothing to do
Exit Sub
End If
On Error GoTo ErrorHandler
' Now add a button to the new toolbar
Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)
Set cButton = oToolbar.Controls.Add(Type:=msoControlButton)
Set dButton = oToolbar.Controls.Add(Type:=msoControlButton)
Set eButton = oToolbar.Controls.Add(Type:=msoControlButton)
' And set some of the button's properties
With oButton
.DescriptionText = "This is my first button" 'Tooltip text
when mouse if placed over button
.Caption = "Kaup PresBuilder" 'Text if Text in Icon is
chosen
.OnAction = "Forming" 'Runs the Sub Button1() code when
clicked
.Style = msoButtonIconAndCaption ' Button displays as icon,
not text or both
.FaceId = 52 '52 is my favorite pig; chooses icon #52
from the available Office icons
End With
' And set some of the button's properties
With cButton
.DescriptionText = "This is my second button" 'Tooltip text
when mouse if placed over button
.Caption = "Kaup Template" 'Text if Text in Icon is chosen
.OnAction = "NewFrom_Template" 'Runs the Sub Button1() code
when clicked
.Style = msoButtonIconAndCaption ' Button displays as icon,
not text or both
.FaceId = 53 '52 is my favorite pig; chooses icon #52
from the available Office icons
End With
' And set some of the button's properties
With dButton
.DescriptionText = "This is my second button" 'Tooltip text
when mouse if placed over button
.Caption = "P&aste Special&" 'Text if Text in Icon is
chosen
.OnAction = "PasteasUnformattedText" 'Runs the Sub Button1()
code when clicked
.Style = msoButtonIconAndCaption ' Button displays as icon,
not text or both
.FaceId = 50 '52 is my favorite pig; chooses icon #52
from the available Office icons
End With
' And set some of the button's properties
With eButton
.DescriptionText = "This is my second button" 'Tooltip text
when mouse if placed over button
.Caption = "" 'Text if Text in Icon is chosen
.OnAction = "pinOpen" 'Runs the Sub Button1() code when
clicked
.Style = msoButtonIconAndCaption ' Button displays as icon,
not text or both
.FaceId = 52 '52 is my favorite pig; chooses icon #52
from the available Office icons
End With
' Repeat the above for as many more buttons as you need to add
' Be sure to change the .OnAction property at least for each new
button
' You can set the toolbar position and visibility here if you like
' By default, it'll be visible when created
oToolbar.Top = 150
oToolbar.Left = 150
oToolbar.Visible = True
NormalExit:
Exit Sub ' so it doesn't go on to run the errorhandler code
ErrorHandler:
'Just in case there is an error
MsgBox Err.Number & vbCrLf & Err.Description
Resume NormalExit:
End Sub
automatically executes without clicking it
Regards
Tyronne
Sub Auto_Open()
Dim oToolbar As CommandBar
Dim oButton As CommandBarButton
Dim cButton As CommandBarButton
Dim dButton As CommandBarButton
Dim eButton As CommandBarButton
Dim MyToolbar As String
' Give the toolbar a name
MyToolbar = "Kaupthing Palette"
On Error Resume Next ' so that it doesn't stop on the next line
if the toolbar's already there
' Create the toolbar; PowerPoint will error if it already exists
Set oToolbar = CommandBars.Add(Name:=MyToolbar,
Position:=msoBarFloating, Temporary:=True)
If Err.Number <> 0 Then ' The toolbar's already there, so we have
nothing to do
Exit Sub
End If
On Error GoTo ErrorHandler
' Now add a button to the new toolbar
Set oButton = oToolbar.Controls.Add(Type:=msoControlButton)
Set cButton = oToolbar.Controls.Add(Type:=msoControlButton)
Set dButton = oToolbar.Controls.Add(Type:=msoControlButton)
Set eButton = oToolbar.Controls.Add(Type:=msoControlButton)
' And set some of the button's properties
With oButton
.DescriptionText = "This is my first button" 'Tooltip text
when mouse if placed over button
.Caption = "Kaup PresBuilder" 'Text if Text in Icon is
chosen
.OnAction = "Forming" 'Runs the Sub Button1() code when
clicked
.Style = msoButtonIconAndCaption ' Button displays as icon,
not text or both
.FaceId = 52 '52 is my favorite pig; chooses icon #52
from the available Office icons
End With
' And set some of the button's properties
With cButton
.DescriptionText = "This is my second button" 'Tooltip text
when mouse if placed over button
.Caption = "Kaup Template" 'Text if Text in Icon is chosen
.OnAction = "NewFrom_Template" 'Runs the Sub Button1() code
when clicked
.Style = msoButtonIconAndCaption ' Button displays as icon,
not text or both
.FaceId = 53 '52 is my favorite pig; chooses icon #52
from the available Office icons
End With
' And set some of the button's properties
With dButton
.DescriptionText = "This is my second button" 'Tooltip text
when mouse if placed over button
.Caption = "P&aste Special&" 'Text if Text in Icon is
chosen
.OnAction = "PasteasUnformattedText" 'Runs the Sub Button1()
code when clicked
.Style = msoButtonIconAndCaption ' Button displays as icon,
not text or both
.FaceId = 50 '52 is my favorite pig; chooses icon #52
from the available Office icons
End With
' And set some of the button's properties
With eButton
.DescriptionText = "This is my second button" 'Tooltip text
when mouse if placed over button
.Caption = "" 'Text if Text in Icon is chosen
.OnAction = "pinOpen" 'Runs the Sub Button1() code when
clicked
.Style = msoButtonIconAndCaption ' Button displays as icon,
not text or both
.FaceId = 52 '52 is my favorite pig; chooses icon #52
from the available Office icons
End With
' Repeat the above for as many more buttons as you need to add
' Be sure to change the .OnAction property at least for each new
button
' You can set the toolbar position and visibility here if you like
' By default, it'll be visible when created
oToolbar.Top = 150
oToolbar.Left = 150
oToolbar.Visible = True
NormalExit:
Exit Sub ' so it doesn't go on to run the errorhandler code
ErrorHandler:
'Just in case there is an error
MsgBox Err.Number & vbCrLf & Err.Description
Resume NormalExit:
End Sub