Adding NET Support to Office

Since your installation of Office 2007 may not have .NET support enabled, you need to check that this feature has been selected; it is required in order to create Shared add-ins. To check whether.NET support is enabled, you need to run Office install. In Windows Vista, first select Programs in the Control Panel, then Programs and Features, then select the Microsoft Office item, as shown in Figure 16.1. If you are running Windows XP, start by selecting the Add or Remove Programs applet in the Control Panel, then the Microsoft Office 2007 item.

FIGURE 16.1

Changing the Office 2007 installation in Windows Vista.

FIGURE 16.1

Changing the Office 2007 installation in Windows Vista.

On the next screen, shown in Figure 16.2, select the Change option, then "Add or Remove Features" for Vista, or the "Add or Remove Features" option for Windows XP

In the Installation Options dialog, drop down the Microsoft Office Access list; if the .NET Programmability Support item has a big red X, that means that it is not installed. To install it, drop down its list and select the "Run from My Computer" item (see Figure 16.3).

Selecting the "Add or Remove Features" option for changing Office in Windows XP.

FIGURE 16.3

Selecting the "Run from My Computer" option for .NET programmability support.

FIGURE 16.3

If you want to create add-ins for any other Office components, select "Run from My Computer" for their .NET Programmability Support components as well. After clicking Continue, Office installs the new features, and when it is done, you will get a success screen, depicted in Figure 16.4; click Close on this screen, and then close the Add/Remove Program applet.

FIGURE 16.4

The success screen after changing the Office configuration.

FIGURE 16.4

The success screen after changing the Office configuration.

Although VB 2005 Express has an Upgrade Wizard, it isn't helpful in upgrading a VB 6 COM add-in to VB 2005 because the Express edition of VB 2005 doesn't support creating add-ins. If you attempt to upgrade a VB 6 COM add-in with this wizard (or the similar wizard in Visual Studio 2005), all the project components will be upgraded except the critical Access Designer, and you will get a message "ActiveX Designer AccessDesigner.Dsr was not upgraded" in the Upgrade Report, as shown in Figure 16.5.

The Upgrade Report for a VB 6 COM add-in, showing that the Access Designer was not upgraded.

^ LNC Control Renaming.vbp Upgrade Report - Microsoft Internet Explorer

■ File Edit View Favorites Tool? Help | ijjf

j Back O' a® P Search # Favorites & [_ > & ß| • □ £

i Address ¿T] mentsWriting Copy\Off ice BoottSample DatabaseslVB 2005 Express COM Add-inl UpgradeReport.htm v. t^} Go j Links Ä ; Norton Antivirus & -

Upgrade Report for LNC Control Renaming.vbp

i

Time of Upgrade: 9/24/2006 3:07 PM

Upgrade Summary

Types of Issues Found Learn More _J Count

There were some differences found that may causes □ Warnings unexpected results when your application is run. You should 1

test your application thoroughly to verify that it functions as

0 Some proiect items were not upgraded Project item was not uparaded 1

B (Global Issues) 1 # Location Object Type Object Name Property Description

1 ActiveX Desioner AccessDesianer.Dsr was not unoraded,

Total 1

B Details For Each File in Project

New Filename Original Filename File Type Status Errors Warnings Total Issues

B (Global Issues) 0 1 1

# Severity Location Object Type Object Name Property Description

11 Global Warning 1 ActiveX Desianer AccessDesianer.Dsr was not uparaded.

B ACCESSDESIGNER.dsr AccessDesigner.Dsr ActiveX Designer Not upgraded 0 0 0 0 COMAddln.vb COMAddln.frm Form Upgraded 0 0 0 B SharedCode.vb SharedCode.bas Module Upgraded 0 0 0

-

3 Fiie(s) Forms: 1 Upgraded: 2 0 1 1 Modules: 1 Not upgraded: 1 ActiveX Designers: 1

Click here for help with troubleshooting upgraded projects

Y, The VB 6 COM add-in was the topic of Chapter 13.

You might think that Visual Studio Tools for Office 2005 (VSTO) would be an appropriate tool for creating Access add-ins, when supplemented with the downloadable upgrade that supports Office 2007 — after all, Access is part of Office. But this is not so. Though you can create add-ins for all the other major Office 2007 components, and some minor ones as well (see Figure 16.6), you can't create an Access add-in with VSTO, and therefore in this section I use Visual Studio 2005 for creating a Shared add-in (this is the new name for what was previously called a COM add-in).

To create a Shared add-in that adds capability to Access, start by running Visual Studio 2005 and selecting File C New Project. In the New Project dialog, select the Extensibility selection under the Other Project Types category, then select the Shared Add-in template. Enter the add-in's name and solution name; you can either accept the default location for the add-in's files or browse for a custom location, as I did in Figure 16.7.

FIGURE 16.6

The VSTO New Project Office screen, showing that Access add-in creation is not supported.

i Project _[US

Q Visual Basic ! Windows 8 Office

1 2003 Add-ins 2007 Add-ins 0 Smart Device Database Starter Kits Test

Distributed System Solutions i±i Other Project Types ffl Test Projects

Visual Studio installed templates

Excel Add-in InfoPath Outlook Add-in PowerPoint Visio Add-in Add-in Add-in m

Word Add-in My Templates

a &

A project for creating a managed code add-in for Excel.

Location: | D:\Documents\Visual Studio 2005\Pro)ects

Solution Name: ExcelAddlnl

[•/I Create directory for solution ill

FIGURE 16.7

Creating a Shared add-in in Visual Studio 2005.

The add-in's name can't contain spaces or punctuation marks — just letters and numbers. However, the solution name can contain spaces or punctuation marks.

caution

After clicking OK, you will get a "Welcome to the Add-in Wizard" screen, as seen in Figure 16.8

The first screen of the Shared Add-in Wizard.

Shared Add-in Wizard 1 F lierai

Welcome to the Add-in Wizard.

_i j a J

This wizard will gather information and create the code for an Add-in. You can then customize this Add-in to your preferences to add functionality to the host application.

[ < Back Next > | Cancel ]

Running Visual Studio 2005 in Windows Vista

In order to run Visual Studio 2005 on Windows Vista, you need to install a Service Fack and then a hotfix. The first download to install is the Visual Studio 2005 Service Pack 1, which can be downloaded from http://msdn2.microsoft.com/en-us/vstudio/bb2 65237.aspx (in various versions depending on the edition of Visual Studio). The hotfix is called the Visual Studio 2005 Service Fack 1 Update for Windows Vista Beta; it can be downloaded at http://www.microsoft.com/down-loads/details

.aspx?familyid=fb6bb56a-10b7-4c05-b81c-58632 84503cf&displaylang=en.

After installing the service pack and hotfix, when you run Visual Studio 2005, you will probably get this message:

I Microsoft Visual Studio 1

Mitra Uifl m Visual Studio2DQ5

Administrator permissions are recommended for running Visual Studio 2005 SP1

Some Visual Studio 2005 tasks and scenarios will not work without Administrator permissions. We recommend that you use Run as administrator' to launch Visua Studio.

Administrator permissions are recommended for running Visual Studio 2005 SP1

Some Visual Studio 2005 tasks and scenarios will not work without Administrator permissions. We recommend that you use Run as administrator' to launch Visua Studio.

Choose Check for Updates fro m the Help Menu to ensure you have the latest updates

Click hereto fearn more about using Visual Studio on Windows Vistd [V] Always s how this message

Continue ] Bret Visual Studio continued continued

If you click on the link, you will get a Web page with more links to pages with information about running Visual Studio 2005 on Vista:

Visual Studio on Windows Vista - Windows Internet Explorer j, j ® nttp://mi£lri.mlcroscift.«m/en-ui/vstudio/a39ia353,M[>x7kid=L033

Visual Studio on Windows ,.. 9 visual Studio on Windo.

Welcome | Sign In msdn

MSDN H

Developer Centers Library Downloads

Visual Studio on Windows ,.. 9 visual Studio on Windo.

Developer Centers Library Downloads

Visual Studio Home Visual Studio Team System Visual Studio Express

▼ Learn Visual Studio Reference

- Support

Support: Overview

Visual Studio 2005 SP1

Visual Studio 2005 and Daylight Saving Time Change

Uninstalling Previous Versions of Visual Studio 2005

Visual Studio H

> Support > Visual Studio on Windows Vista

Visual Studio on Windows Vista

The release of the Windows Vista operating system represents a significant opportunity for developers to build the next generation of applications that deliver compelling user experiences. We want to help you take advantage of this opportunity and assist you in developing and delivering Windows Vista based software faster, more cost effectively, and with greater impact than ever before.

During the development of Windows Vista, several key investments were made to vastly improve overall quality, security, and reliability from previous versions of Windows. We're also testing to ensure that your .NET Framework 1.1 and 2.0 applications will work on Windows Vista so that your existing applications will continue to run as

While we have made tremendous investments in Windows Vista to ensure backwards compatibility, some of the system enhancements, such as User Account Control, changes to the networking stack, and the new graphics model, make Windows Vista behave differently from previous versions of Windows.

able to support Visual Studio .NET 2002 or Visual iwever, your existing .NET Framework 1.1 and 2.0 based applicatioi II be able to take advantage of many of the new features available is Vista a pp I i cat or more information about the impact of Windo* Visual Studio on Windows Vista FAQ Visual Studio 2005 on Windows Vista Issue Li;

; Vista on Visual Studio ple<

il Studio 2005 o

Windol.

;t - Running with elevated adm

Visual Studio -NET 2003 on Windows Vista Issue List Microsoft released Visual Studio 2005 Service Pack 1 and the beta of the Visual Studio 2005 SP1 Update fc Windows Vista. For more information, see Visual Studio 2005 Service Pack 1. To submit feedback on the V Studio o is Vista is as, pies it Microsoft Conner

Internet | protected Mode: on

For running Visual Studio 2005 on Vista, the link you need is the third one, "Running with elevated administrator permissions." There is a lot of information on this page, but basically you only need one thing: when running Visual Studio in Vista, right-click its icon and select "Run as administrator" from its context menu:

gig Screen Shot Standard 3 ¡1 Microsoft Office Word 2007

XML Notepad 2007 Xjf) Microsoft Visual Studio 2005 ijggl MSE7.EXE

Digital Certificate for VBA Projects Windows Media Center

Windows Media Player

Windows Photo Gallery

Windows Lit"mate Extras

V All Programs

Open

Open file location

Run as administrator k

WinZip

Unpin from Start Menu

Add to Quick Launch Scan for viruses». Restore previous versions Send To Copy

Remove from this list Rename

Properties

Properties

Now you can create new projects or open existing projects, and work with them as in Windows XP, and your Visual Studio add-in Ribbons (and other customizations) will work in Access 2007 databases.

On the screen depicted in Figure 16.9, select Visual Basic as the programming language to use (it may be the only choice, depending on the language support you selected when installing Visual Studio).

FIGURE 16.9

Selecting a programming language for the add-in.

FIGURE 16.9

Selecting a programming language for the add-in.

On the next screen, shown in Figure 16.10, select Microsoft Access as the application host.

FIGURE 16.10

Selecting an application host for the add-in.

FIGURE 16.10

Selecting an application host for the add-in.

On screen 3 of the wizard (see Figure 16.11), enter the add-in's name and description (not the same as the project name and solution name entered on the first screen).

FIGURE 16.11

Giving the add-in a name and description.

FIGURE 16.11

Giving the add-in a name and description.

Next, as depicted in Figure 16.12, select add-in options — during development, it's best to check only the first checkbox, so only you (the developer) can work with the add-in.

FIGURE 16.12

Selecting add-in options.

FIGURE 16.12

Selecting add-in options.

The final page of the Shared Add-in Wizard (see Figure 16.13) gives a summary of the selected options.

FIGURE 16.13

The Summary page of the Shared Add-in Wizard.

FIGURE 16.13

The Summary page of the Shared Add-in Wizard.

On clicking Finish, the new add-in project is created, with all the necessary components, and the Connect class (the Connect.vb module) is displayed, as shown in Figure 16.14 (note the similarity to the Access Designer in the VB 6 COM add-in). To work with the references more easily, select Project C Show All Files, and expand the References folder in the Solution Explorer at the right of the screen.

r—:—T

r i p-v

__T

1Jr r- ■ ■:. £ (

If you don't see the References folder in the Solution Explorer, select Show All Files from the Project menu to make the folder visible.

The new Shared add-in project.

The new Shared add-in project.

Next, add a reference to the Access Interoperability item. To add references, right-click the References folder and select Add Reference, then select the .NET tab, select "Microsoft.Office.Interop.Access" (as in Figure 16.15), and click OK.

Figure 16.16 shows the solutions references in the Solution Explorer.

FIGURE 16.15

Adding a reference to the Interop.Access item.

Add Reference |i£5»| •MET [ COM | Projects | Browse | Recent |_

Component Name

Version

Runtrm

Microsoft. Bui 1 d, Fram ework

2HD£

V20.50J

Microsoft Buitd.Tasks

2BBB

V2.0507

Microsoft. Build.Utilities

2,0.0.0

V2.0J01

M i crosoft. Bu i 1 d. Visu a IJSh a rp

was

v2,050;

Microsoft. CompactFramework.Build.Tasks

8,0.0.0

v2,0.50i

MicrosoftJScript

80.0.0

v2.050]

J

Microsoft, mshtml

7,0.3300 a

vl,0.37C

Microsoft.Office.InfoPath.Client.Internal.CLRH...

12.0.0.0

v2,050i

Microsoft. Office.InfoPath.FormControl

12.0 J) B

V2.0301

Microsoft. Off ice.interop.a ccess. d a o

12.0 BB

vll.43

Micros oft. Off ice.Interop.Excel

12.0.0,0

vl,1.43

Microsoft. Off ice.Interop.Graph

12XU)D

vli.43

Microsoft. Off ice.InteropJnfoPath

12.0 .Ofl

vl 143

Microsoft. Off ¡ce.Interop.InfoPath.Sem ¡Trust

11.0J)B

vli.43;

Microsoft. Off ice.InteropJnfoPath .Xml

12.0.0,0

vl,1.43

Microsoft. Offi ce.Interop.Outl ook

12.0.0.0

vli.43i

Microsoft. Off i ce.Interop.O utl ookViewCtl

12.0.0,0

vl,1.43

Microsoft. Offi ce.Interop.PowerP oint

1ZOBJO

vl.1.43

M i r mi oft. Off i r p. in tprn ri. P r i hi i ç h pr

1211.0 0

vl 1

FIGURE 16.16

The Access Interoperability reference, and standard references.

^ Solution 'Create Objects' (2 projects) iyp CreateObjects m My Project (=)•• LjT References

•Q Extensibility Microsoft.Office.Core

Mfcrosoft.OfficeJnterop Access j™. System

•O System. Data L System.XML bin

^ Assem blylnfo.vb ^ Connect.vb □ ^J Create ObjectsSetup El- & Detected Dependencies vig Microsoft,NET Framework

I jp Office.dll

Primary output from CreateObjects (A

The next step is to add some Imports statements under the two default statements in the Declarations section of the class module, using IntelliSense (see Figure 16.17):

Imports Extensibility

Imports System.Runtime.InteropServices Imports Microsoft.Office.Core

Imports Access = Microsoft.Office.Interop.Access

FIGURE 16.17

Using IntelliSense to add an Imports statement to the Connect class module.

imports Extensibility 1mports System.Runtime.InteropSeruices Imptlrts Microsoft.Office.Core imports Microsoft .Off ice. I nt erop.;

Bl Read fie for ftdd-in installatj jjHame5paieAcee.5h|

E <Kui<llttt|-ti>«t»( 9B2 l71^F0-66tl^-'l9B6d2l;D-(l5(l^"36fl29O25,,) , Priiqlilflt.tr Public Class Connect

]mplerients Extensibility -IDTExtensibility2

Dim applicationObject as Object Oim addInInstance as object

Public Sub OnBeginShutdowntBijRef custom Bs System.Array) Inple

Next, replace the class-level variables (applicationObject and addInInstance), both declared as Object, with typed references, replacing Dim with Private (I also gave the applicationObject variable a more application-specific name, appAccess):

Private appAccess As Microsoft.Office.Interop.Access.Application Private addInInstance As Microsoft.Office.Core.COMAddIn

After adding statements and modifying the variables, there are some more modifications to be made to the code in the Connect class module. These changes are described in the next section.

0 0

Post a comment