Picture-Property outside an application not possible?

P

Peter Marchert

Hello together,

I want to load a own picture to a CommandBarButton outside the
application where it ist used. For example: I try to create a button in
word from excel vba. To do this I set a reference to word. Here ist the
code:

Sub Test()

Dim objCommandBar As Office.CommandBar
Dim objButton As Office.CommandBarButton
Dim pic1 As stdole.IPictureDisp
Dim msk1 As stdole.IPictureDisp

Set pic1 = stdole.StdFunctions.LoadPicture("C:\pic1.bmp")
Set msk1 = stdole.StdFunctions.LoadPicture("C:\msk1.bmp")

Set objCommandBar = Word.Application.CommandBars.Add(Name:="TEST",
Temporary:=True)
Set objButton = objCommandBar.Controls.Add(Type:=msoControlButton)

With objButton
.Style = msoButtonIcon
.Picture = pic1
.Mask = msk1
.Caption = "Test"
End With

objCommandBar.Visible = True

End Sub

The code does not work. Only if the same code is placed in Word there
is no problem.

The faceId-Property I don`t want to use, because the same button is
used on another place with a userdefined picture.

Is it not possible or is there a workarround?

Thanks for any help or suggestions!

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top