Menus and Toolbars

Vertex42 The Excel Nexus

Professional Excel Templates

Get Instant Access

Most of the Office 2003 menus and toolbars available in Word or Excel are available in Visual Studio. For example, in an Excel workbook solu tion you will notice that the designer (Excel) contains the toolbars. You can show and hide the toolbars by right-clicking the toolbar and clicking a toolbar on the context menu, as shown in Figure 2.7.

Figure 2.7. Selecting a new toolbar for the Excel designer

These toolbar buttons work exactly as they would if you were using the application outside Visual Studio. However, VSTO disables some of these toolbar commands, including the command to customize the toolbar itself. Notice that the Customize menu item is grayed out in Figure 2.7. If you want to customize a toolbar in VSTO, you have to write code.

Notice also that there are no menu items directly above the toolbars for the Excel designer. The same is true for the Word designer. Instead, VSTO merges the menus and menu items with the Visual Studio menus. VSTO organizes these menus and menu items so that the ones particular to Word or Excel are available only when the Word or Excel designer has focus. If you move focus to an area of Visual Studio outside the designer, only the Visual Studio menu items are available.

For example, if you select an Excel worksheet so that it has focus, you will see menus that are specific to Excel, such as the Insert menu. The Insert menu is not visible if Visual Studio has focus. If a menu in Excel already exists in Visual Studio, VSTO merges the menu items, placing the Excel-specific functionality in a cascading menu. Figure 2.8 shows the menu merging that takes place in the Data menu when Excel has focus, and Figure 2.9 shows the Data menu when Visual Studio has focus.

File Edfc View

Project Build Debug Data Tool:

l..,t F„

mat Window Cart

munity Help

i £1 • iJ bid. * H a J a V

A

ntik.nl-ï i j a

• ii-i'

AddHevj Dare soiree.

Subtotals... Vefefekfcn...

a is iï _ . ;

- a -

•ià a. 1 m Si,

M

s

- ¡jf SampleWcWjock. xls jJSheedvb J) Sheet2.vb j]She«3.vb àj ThsWortoook.vb : 'm My Project

A

b

c

S

f

f

Table.,,

K

L

M

M

1

Te it to Coljrns... consolidate...

Group and outfnfe »

2

A

PiwStTable îiid FSvotChaft Report.,, import external Data ► List ► XM. ►

b 6

! 8

-JSolutionEiptrer ^]oata Sources

To

IwniM

Sheet 1 Micro5oft.offic«.Tools,Excel/ ■

Figure 2.8. Selecting an Excel command in the Data menu

File

eat vie

Project

in 1 Hbua i Dace^ 1 r.-'.k wir Ji .1 zotrtmMr Heft

3 -.

g s'a*

-igt?11

,n * j • A jt -. - - l-J Sh«vC>attSou(«M 5htft+Afc+D ,;

A .

J

w g ; ^

19 * !

i y

m m m a - -Jt a *

a»-A-

a j-J L«.

A1

r.

H] ThjWBfliKWk.Vb ^ My PreiwJ

T

A

c

0

F

F

g

H

i

»

k

1

m

N

-

2

3

4

6

7

G 9

uujim^^^huj

10

Sheet l.vb Rie Properties

Figure 2.9. Selecting a Visual Studio command in the Data menu

Figure 2.9. Selecting a Visual Studio command in the Data menu

This menu merging can take a little getting used to. If you can't find a command in the menu, remember that the document designer must have focus for you to view the Word or Excel menu items. First select the document or worksheet, and then you should be able to locate the command.

Because there is no design surface for add-in solutions, no menu merging takes place. You have access only to the code view in the Visual Studio editor, and thus only the Visual Studio menus and toolbars are available when you create an add-in.

Was this article helpful?

0 0

Post a comment