Well, I'm using C++. Here's the relevant code (with unnecessary code
removed):
CComQIPtr<Office::_CommandBarButton> m_pSaveButton;
CComPtr<Office::_CommandBars> m_pCommandBars;
CComPtr<Office::CommandBar> m_pCommandBar;
{
m_pCommandBar = m_pCommandBars->Add(CComVariant(toolBarName),
CComVariant(msoBarTop), CComVariant(VARIANT_FALSE),
CComVariant(VARIANT_TRUE));
// Now get the tool bar's CommandBarControls
CComPtr<Office::CommandBarControls>
pBarControls(m_pCommandBar->GetControls());
// Add save button
m_pSaveButton = pBarControls->Add(CComVariant(msoControlButton),
vEmpty, vEmpty, vEmpty, CComVariant(VARIANT_TRUE));
// Set properties
m_pSaveButton->PutStyle(Office::msoButtonIconAndCaption);
m_pSaveButton->PutFaceId(1677);
m_pSaveButton->PutVisible(VARIANT_TRUE);
m_pSaveButton->PutEnabled(VARIANT_TRUE);
// Set caption
m_pSaveButton->put_Caption(caption);
}
I figured out that later on, when I get the OnClick notification, I can set
the caption just fine using the interface that is passed in to the function:
void __stdcall ToolBar::OnClickButton(IDispatch* Ctrl, VARIANT_BOOL *
CancelDefault)
{
CComQIPtr<Office::_CommandBarButton> pButton(Ctrl);
pButton->put_Caption(caption);
}
The funny thing is that the icon and the tooltip text work just fine. So
I'm confused...
Mark