File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Rubberduck.VBEEditor/SafeComWrappers/Office.Core Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 2
2
using System . Collections ;
3
3
using System . Collections . Generic ;
4
4
using System . Linq ;
5
+ using System . Runtime . InteropServices ;
5
6
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
6
7
using Rubberduck . VBEditor . SafeComWrappers . MSForms ;
7
8
using Rubberduck . VBEditor . SafeComWrappers . Office . Core . Abstract ;
@@ -17,14 +18,33 @@ public CommandBars(Microsoft.Office.Core.CommandBars target)
17
18
18
19
public ICommandBar Add ( string name )
19
20
{
21
+ DeleteExistingCommandBar ( name ) ;
20
22
return new CommandBar ( Target . Add ( name , Temporary : true ) ) ;
21
23
}
22
24
23
25
public ICommandBar Add ( string name , CommandBarPosition position )
24
26
{
27
+ DeleteExistingCommandBar ( name ) ;
25
28
return new CommandBar ( Target . Add ( name , position , Temporary : true ) ) ;
26
29
}
27
30
31
+ private void DeleteExistingCommandBar ( string name )
32
+ {
33
+ try
34
+ {
35
+ var existing = Target [ name ] ;
36
+ if ( existing != null )
37
+ {
38
+ existing . Delete ( ) ;
39
+ Marshal . FinalReleaseComObject ( existing ) ;
40
+ }
41
+ }
42
+ catch
43
+ {
44
+ // specified commandbar didn't exist
45
+ }
46
+ }
47
+
28
48
public ICommandBarControl FindControl ( int id )
29
49
{
30
50
return new CommandBarControl ( Target . FindControl ( Id : id ) ) ;
You can’t perform that action at this time.
0 commit comments