Ik heb een Word project gemaakt (visual studio tools for office). En deze creeert netjes een menuitem en knop er onder. Dit is allemaal nog om te leren hoe het kan dus, er gebeurt nog niks spannends. Het werkt allemaal prima. Alleen als ik Word opnieuw opstart, buiten VS.NET of via VS.NET, dan staat mijn MenuItem er nog. Dit terwijl hij temporary op true heeft staan. Daarnaast komt er iedere keer een MenuItem bij als ik mijn project run in VS.NET
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| protected void ThisDocument_Open() { InitMenuBarItems("&AccoNet"); MenuItemOpen = CreateButton((Office.CommandBarPopup)MenuBarItem, "Maak tabel met alle gebruikers"); MenuItemOpen.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(MenuItemOpen_Click); } /// <summary> /// Called when the document is closed. /// </summary> protected void ThisDocument_Close() { // Ensure that Close is not called twice. designModeClose = false; } private void InitMenuBarItems(string Caption) { try { MainMenuBar = ThisApplication.CommandBars["Menu Bar"]; MenuBarItem = MainMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true); MenuBarItem.Caption = Caption; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } } private Office.CommandBarButton CreateButton( Office.CommandBarPopup Parent, string Caption) { Office.CommandBarControl cbc = null; try { cbc = Parent.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, true); cbc.Caption = Caption; cbc.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } return (Office.CommandBarButton) cbc; } |