View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Toggle Design Mode in Excel by AddIn

It is very simple in VBA. The following procs will turn design mode on or
off.

Sub TurnOffDesignMode()
Const DESIGN_MODE_ID As Long = 1605&
Dim Ctrl As Office.CommandBarButton
Set Ctrl = Application.CommandBars.FindControl(ID:=DESIGN_MOD E_ID)
With Ctrl
If .State = msoButtonDown Then
.Execute
End If
End With
End Sub

Sub TurnOnDesignMode()
Const DESIGN_MODE_ID As Long = 1605&
Dim Ctrl As Office.CommandBarButton
Set Ctrl = Application.CommandBars.FindControl(ID:=DESIGN_MOD E_ID)
With Ctrl
If .State = msoButtonUp Then
.Execute
End If
End With
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


wrote in message
...
On 20 ÎÏÑÂ, 15:04, wrote:
How could AddIn toggle Design mode in Excel? I'm talking about some
functionality like Workbook.ToggleFormsDesignMode for Excel 2007. How
could it possible for older versions?

Thank you in advance.


So, we've found it out. There is an example of code in C++ for our
AddIn. It works fine for Excel 2003 and 2007:


Excel::_ApplicationPtr pApp = NULL;

pApp = m_pParentApp;

if (pApp == NULL)
{
MessageBox(NULL, "Can't get Excel::_Application interface", "Test
Addin", MB_SETFOREGROUND);
}
else
{
try
{
Excel::_WorkbookPtr wb_ptr;

wb_ptr = pApp-GetActiveWorkbook();

wb_ptr-ToggleFormsDesign();
}
catch (_com_error err)
{
MessageBoxW(NULL, err.Description().GetBSTR(), L"Test Addin",
MB_SETFOREGROUND);
}
}



Thanks for attention, we hope it'll be useful for community.