Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF

Put an image on the clipboard to use as a custom toolbar icon

Problem

You want to use a custom image for a toolbar icon instead of one of the built-in Office icon buttons.

You know you can use .PasteFace to paste an image from the clipboard onto a button face, but how to get the image on the clipboard in the first place?

Solution

Here's one possible solution:

Sub PutImageOnClipboard()

    Dim oPres As Presentation
    Dim oSh As Shape
    Dim strIconFile As String

    ' Edit this to point to the file you want to put on clipboard
    strIconFile = "C:\Pictures\SomeImage.GIF"

    ' Add a new presentation (WithWindow set to False)
    Set oPres = Presentations.Add(msoFalse)
    ' add a slide
    Call oPres.Slides.Add(1, ppLayoutBlank)

    ' Import the picture at any arbitrary size
    Set oSh = oPres.Slides(1).Shapes.AddPicture(FileName:=strIconFile, _
        LinkToFile:=msoFalse, _
        SaveWithDocument:=msoTrue, _
        Left:=0, Top:=0, width:=10, height:=10)

    ' Set the picture back to its rightful size, then copy and delete it
    With oSh
        .Scaleheight 1, msoTrue
        .Scalewidth 1, msoTrue
        .Copy
        .Delete
    End With

    ' clean up
    oPres.Close
    Set oPres = Nothing

End Sub

And here's another approach
Peter Farge posted this example code in the PowerPoint Newsgroup:

  1. Create a form "UserForm1" with an image control named "Image1"
  2. Load a picture in the image control.
  3. Create a module and add the following code to it:

Public Sub CreateCommandBar()
   Dim oComBar As CommandBar
   Const COMMANDBAR_NAME As String = "Test toolbar"

   ' Delete old toolbar:
   For Each oComBar In CommandBars
      If oComBar.Name = COMMANDBAR_NAME Then
         oComBar.Delete
      End If
   Next oComBar

   ' Create new toolbar:
   Set oComBar = Application.CommandBars.Add(COMMANDBAR_NAME)
   Call AddButton(oComBar, "Button Caption", _
          "CMDBAR_FunctionDoSomething", UserForm1.Image1.Picture, True)
   oComBar.Visible = True
End Sub

Private Sub AddButton(oComBar As CommandBar, sButtonName As String,
sMakroName As String, oIcon As IPictureDisp, bBeginGroup As Boolean)
   Dim oComBarButton As CommandBarButton

   Set oComBarButton = oComBar.Controls.Add(msoControlButton)
   With oComBarButton
      .Caption = sButtonName
      .OnAction = sMakroName
      .BeginGroup = bBeginGroup
      .Style = msoButtonIcon
      .Picture = oIcon
   End With
End Sub

Public Sub CMDBAR_FunctionDoSomething()
   MsgBox "Hello toolbar"
End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.

Search terms:pasteface,paste,face,clipboard,image,graphic


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2015 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.
Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Put an image on the clipboard to use as a custom toolbar icon
http://www.pptfaq.com/FAQ00495_Put_an_image_on_the_clipboard_to_use_as_a_custom_toolbar_icon.htm
Last update 07 June, 2011
Created: