• Commandbutton.Picture from outside App. (2003)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Commandbutton.Picture from outside App. (2003)

    Author
    Topic
    #429039

    Hi, i have seen from a Google that the following code in VB6 which is part of a custom install, publish and set up of a Form for Outlook (below is the ‘add toolbar button’ bit) will not work. The IPictureDisp object apparently cannot be used from outside the VBA when it comes to the .Picture and .Mask method.

    Guess what my question is… evilgrin
    Yes, is there ANY WAY to programmatically add an icon image to a newly created toolbar button from outside Outlook ? I am not so hopeful, i know there is an ‘addin’ method documented by MS, I suppose it would be possible to make this add-in, then ‘add it’ via the VB6 and run it so that it does what i want.

    Alternatively, i may have to just leave it with text, or a default image…. and I spent all that time making my icon and mask!! Oh well…

    Dim picon As stdole.IPictureDisp, pmask As stdole.IPictureDisp
    Set pIcon = stdole.StdFunctions.LoadPicture(“C:OutlookFormsImage.bmp”)
    Set pMask = stdole.StdFunctions.LoadPicture(“C:OutlookFormsMask.bmp”)
    ‘ add the button
    Set cmdbt = cb.Controls.Add(1) ‘ msoControlButton
    With cmdbt
    .Caption = “button1”
    .BeginGroup = True
    .HyperlinkType = 1 ‘ msoCommandBarButtonHyperlinkOpen
    .ToolTipText = ‘ hyperlink here
    .Style = 3 ‘ textandIcon
    .Picture = pIcon
    .Mask = pMask
    .Visible = True
    End With

    Viewing 0 reply threads
    Author
    Replies
    • #998207

      The following code (based on the built-in help) works for me in Outlook 2002:

      Sub Test()
      Dim cbr As CommandBar
      Dim cbb As CommandBarButton
      Dim picPicture As IPictureDisp
      Dim picMask As IPictureDisp
      Set cbr = ActiveExplorer.CommandBars.Add(“Test”, , , True)
      cbr.Visible = True
      Set cbb = cbr.Controls.Add(msoControlButton, , , , True)
      Set picPicture = stdole.StdFunctions.LoadPicture(“c:imagespicture.bmp”)
      Set picMask = stdole.StdFunctions.LoadPicture(“c:imagesmask.bmp”)
      With cbb
      ‘Set the style
      .Style = msoButtonIcon
      ‘Set the button image.
      .Picture = picPicture
      ‘Set the mask.
      .Mask = picMask
      End With
      Set picMask = Nothing
      Set picPicture = Nothing
      Set cbb = Nothing
      Set cbr = Nothing
      End Sub

      • #998209

        Sorry, I didnt make myself clear I dont think. I am running the code from VB6, in an exe file. In this sense it is outside the Outlook Application. I can manipulate everything apart from the .Picture and .Mask methods.

        • #998212

          Sorry, can’t help then.

          • #998214

            No worries, I think the amount of work is not worth it just for a custom icon

            Settled for

            cmdbt.FaceID = 2687

            which gives an appropriate icon that my manager is happy with

            have a good weekend Hans

    Viewing 0 reply threads
    Reply To: Commandbutton.Picture from outside App. (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: