1.第一种方法
Word::_DocumentPtr pDoc = m_lpDispatch;
if (pDoc )
{
Office::_CommandBarsPtr pbars= pDoc -> GetCommandBars ();
if (NULL == pbars)
{
lstrcpy(g_tszErrorMsg,_T( "获取excel的GetCommandBars接口失败! "));
return E_FAIL;
}
Office::CommandBarPtr pbar;
_bstr_t bstrCommandName = _T( "Standard ");
pbars -> GetItem (bstrCommandName)-> PutVisible (VARIANT_FALSE);
bstrCommandName = _T( "Formatting ");
pbars -> GetItem (bstrCommandName)-> PutVisible (VARIANT_FALSE);
2.第二种方法:
HWND hwnd = FindWindowEx(m_hWnd,NULL, "EXCEL2 ",NULL);
HWND hclosewnd = NULL;
while (hwnd != NULL)
{
hclosewnd = FindWindowEx(hwnd,NULL, "MsoCommandBar ", "工作表菜单栏 ");
if (hclosewnd)
SendMessage(hclosewnd,WM_CLOSE,0,0);
hclosewnd = FindWindowEx(hwnd,NULL, "MsoCommandBar ", "图表菜单栏 ");
if (hclosewnd)
SendMessage(hclosewnd,WM_CLOSE,0,0);
hclosewnd = FindWindowEx(hwnd,NULL, "MsoCommandBar ", "格式 ");
if (hclosewnd)
SendMessage(hclosewnd,WM_CLOSE,0,0);
hclosewnd = FindWindowEx(hwnd,NULL, "MsoCommandBar ", "常用 ");
if (hclosewnd)
SendMessage(hclosewnd,WM_CLOSE,0,0);
hclosewnd = FindWindowEx(hwnd,NULL, "MsoCommandBar ", "图表 ");
if (hclosewnd)
SendMessage(hclosewnd,WM_CLOSE,0,0);
hwnd = FindWindowEx(m_hWnd,hwnd, "EXCEL2 ",NULL);
}