integrate the vba 6 development environment into your application

54
Integrate the VBA 6 Integrate the VBA 6 Development Environment into Development Environment into your Application your Application Rebecca Rinner Rebecca Rinner Senior Software Engineer Senior Software Engineer Summit Software Company Summit Software Company 4-307 4-307

Upload: guido

Post on 02-Feb-2016

40 views

Category:

Documents


0 download

DESCRIPTION

Integrate the VBA 6 Development Environment into your Application Rebecca Rinner Senior Software Engineer Summit Software Company 4-307. Outline. Key benefits of VBA Preparing for VBA Integration Integrating VBA What is APC VBA Integration Architecture Phases of VBA Integration. Outline. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Integrate the VBA 6 Development Environment into your Application

Integrate the VBA 6 Development Integrate the VBA 6 Development

Environment into your ApplicationEnvironment into your Application

Rebecca RinnerRebecca RinnerSenior Software EngineerSenior Software EngineerSummit Software CompanySummit Software Company

4-3074-307

Page 2: Integrate the VBA 6 Development Environment into your Application
Page 3: Integrate the VBA 6 Development Environment into your Application

OutlineOutline

Key benefits of VBAKey benefits of VBA Preparing for VBA IntegrationPreparing for VBA Integration Integrating VBAIntegrating VBA

What is APCWhat is APC VBA Integration ArchitectureVBA Integration Architecture Phases of VBA IntegrationPhases of VBA Integration

Page 4: Integrate the VBA 6 Development Environment into your Application

OutlineOutline

Key benefits of VBAKey benefits of VBA Preparing for VBA IntegrationPreparing for VBA Integration Integrating VBAIntegrating VBA

What is APCWhat is APC VBA Integration ArchitectureVBA Integration Architecture Phases of VBA IntegrationPhases of VBA Integration

Page 5: Integrate the VBA 6 Development Environment into your Application

Visual Basic for ApplicationsVisual Basic for Applications

The premier development technology found in applications that enables your customers to:

Customize Enable customers to tailor yourproduct to their specific needs

Leverage Deliver the power of Visual Basic to leverage the 3+ million VB developers

Integrate Enable customers to create entire line of business solutions

Page 6: Integrate the VBA 6 Development Environment into your Application

Buy vs. BuildBuy vs. Build

Pros Infinite Flexibility Your Code & DataCons High Risk High Cost

Pros Lower Initial Cost Fast DeploymentCons Not Flexible No Advantage

Buy Build

Page 7: Integrate the VBA 6 Development Environment into your Application

Buy and CustomizeBuy and Customize

Competitive Advantage!

Lower Initial Cost

Fast Deployment

Infinite Flexibility

Your Code & Data

Page 8: Integrate the VBA 6 Development Environment into your Application

FlexibilityFlexibility

Your application becomes a Your application becomes a platformplatform Write portions of your application in Write portions of your application in

VBAVBA Change features after you shipChange features after you ship Add features after you shipAdd features after you ship Eliminate one-off feature requestsEliminate one-off feature requests

Create a 3Create a 3rdrd party community party community

Page 9: Integrate the VBA 6 Development Environment into your Application

““Got VBA?”Got VBA?” VBA throughout Office 2000VBA throughout Office 2000

Outlook, FrontPageOutlook, FrontPage 100+ shipping applications 100+ shipping applications New announcements New announcements

every weekevery week

Page 10: Integrate the VBA 6 Development Environment into your Application

Types of ApplicationsTypes of Applications

Traditional “thick client”Traditional “thick client” Multi-threaded applicationsMulti-threaded applications

Multi-threaded designerMulti-threaded designer VBA in the Middle-tierVBA in the Middle-tier

Allows customizable business objectsAllows customizable business objects Duwamish sample on MSDNDuwamish sample on MSDN

Thin clientThin client

Check out the VBA Pavilion!Check out the VBA Pavilion!

Page 11: Integrate the VBA 6 Development Environment into your Application

DEMO

An Application with VBAAn Application with VBA

Page 12: Integrate the VBA 6 Development Environment into your Application

OutlineOutline

Key benefits of VBAKey benefits of VBA Preparing for VBA IntegrationPreparing for VBA Integration Integrating VBAIntegrating VBA

What is APCWhat is APC VBA Integration ArchitectureVBA Integration Architecture Phases of VBA IntegrationPhases of VBA Integration

Page 13: Integrate the VBA 6 Development Environment into your Application

VBA Building Blocks

COM-Enable Your Application

Design and Implement an Object Model

Preparing for VBA Integration

Page 14: Integrate the VBA 6 Development Environment into your Application

VBA Building Blocks…VBA Building Blocks…

Visual Basic Editor (VBE)Visual Basic Editor (VBE)Project ExplorerProject ExplorerCode EditorCode EditorImmediate WindowImmediate WindowProperties WindowProperties WindowLocals, Watch, ...Locals, Watch, ...VBE Object modelVBE Object model

““Visual Basic for Application Visual Basic for Application Extensibility”Extensibility”

Defined in vbe6ext.olbDefined in vbe6ext.olbCodeModuleCodeModuleCommandBarEventsCommandBarEventsVBProjectVBProjectVBComponentVBComponentReferencesReferences......

Page 15: Integrate the VBA 6 Development Environment into your Application

VBA Building Blocks...VBA Building Blocks...

Project HierarchyProject HierarchyVBA ProjectVBA Project

Project ItemsProject ItemsHost project ItemsHost project Items

ControlsControls**

UserFormsUserForms

Code modulesCode modules

Class modulesClass modules

Host classesHost classes****

DesignersDesigners****

* Controls are not visible in the Project Explorer window. They appear only in the Object combo box of the Code Editor** Host Classes and Designers are normally visible in the Project Explorer window, just not this one.

Page 16: Integrate the VBA 6 Development Environment into your Application

VBA Building Blocks...VBA Building Blocks...

VBA Project VBA Project Unit of persistenceUnit of persistence Uses IStorage to load/saveUses IStorage to load/save Often, a 1:1 association with Often, a 1:1 association with

documentsdocuments An application can have multiple VBA An application can have multiple VBA

projectsprojects Contains all code in “Project Items”Contains all code in “Project Items”

Page 17: Integrate the VBA 6 Development Environment into your Application

Project ItemsProject Items Host project itemsHost project items

Simply COM objectsSimply COM objects Expose events to VBAExpose events to VBA Code “behind” (using COM aggregation)Code “behind” (using COM aggregation) Can have controlsCan have controls

Host ClassesHost Classes Just like host project items, except that Just like host project items, except that

you can have multiple instances of themyou can have multiple instances of them

VBA Building Blocks...VBA Building Blocks...

Page 18: Integrate the VBA 6 Development Environment into your Application

VBA Building Blocks...VBA Building Blocks...

Project items...Project items... Code moduleCode module

Contain VBA code onlyContain VBA code only Global Global

Class moduleClass module Creatable VBA classesCreatable VBA classes

UserForms and Other DesignersUserForms and Other Designers UserForms (built-in)UserForms (built-in)

Can be used to build UI for your applicationCan be used to build UI for your application

VB6 DesignersVB6 Designers

Page 19: Integrate the VBA 6 Development Environment into your Application

VBA Building Blocks...VBA Building Blocks... Code ExecutionCode Execution

Macros dialog boxMacros dialog box Named macros executedNamed macros executed

in response to UIin response to UI Toolbar, menu selection, Toolbar, menu selection,

keystrokekeystroke Can pass parametersCan pass parameters

EventsEvents Code behindCode behind

Page 20: Integrate the VBA 6 Development Environment into your Application

VBA Building Blocks

COM-Enable Your Application

Design and Implement an Object Model

Preparing for VBA Integration

Page 21: Integrate the VBA 6 Development Environment into your Application

COM-Enable Your COM-Enable Your ApplicationApplication

Follow the COM SpecificationFollow the COM Specification Adopt the COM PhilosophyAdopt the COM Philosophy Use COM as the Binary Standard for Use COM as the Binary Standard for

Application ComponentsApplication Components For MFC applications, use ATL for For MFC applications, use ATL for

COM support.COM support.

Page 22: Integrate the VBA 6 Development Environment into your Application

COM-Enable Your COM-Enable Your Application... Application...

ApplicationApplication

““Peer”Peer”COM ObjectsCOM Objects

You don’t have to rewrite your You don’t have to rewrite your applicationapplication Use “peer” objectsUse “peer” objects

C++ or MFCC++ or MFCclassesclasses

APC APC VBAVBA

Page 23: Integrate the VBA 6 Development Environment into your Application

COM-Enable Your COM-Enable Your Application... Application...

ApplicationApplication

VB ClassesVB Classes

VB Applications are COM “friendly”COM object model exposed as VB classes

APC APC VBAVBA

Page 24: Integrate the VBA 6 Development Environment into your Application

VBA Building Blocks

COM-Enable Your Application

Design and Implement an Object Model

Preparing for VBA Integration

Page 25: Integrate the VBA 6 Development Environment into your Application

Design and ImplementDesign and Implementan Object Modelan Object Model

Definition: Definition: An Object Model is the set An Object Model is the set of objects, methods, and properties of objects, methods, and properties your application exposes for your application exposes for programmabilityprogrammability

Required for VBA integrationRequired for VBA integration

Page 26: Integrate the VBA 6 Development Environment into your Application

Why Expose an Object Model?Why Expose an Object Model?

Allow your application to be part of bigger Allow your application to be part of bigger solutionssolutions Can be driven by a wide variety of tools Can be driven by a wide variety of tools

(VBA, VB, VC++, Delphi, and others)(VBA, VB, VC++, Delphi, and others) Create a 3rd party community supporting Create a 3rd party community supporting

your productyour product Required for VBA integrationRequired for VBA integration

Page 27: Integrate the VBA 6 Development Environment into your Application

Object Model Design TipsObject Model Design Tips

Use standard constructs and behavior Use standard constructs and behavior Users will already know it.Users will already know it. Users will intuitively understand it.Users will intuitively understand it. VBA will not choke on it.VBA will not choke on it.

Events provideEvents provide Respond to user actionsRespond to user actions Respond to detected conditionsRespond to detected conditions Hook application internalsHook application internals

See the Summit white paperSee the Summit white paper

Page 28: Integrate the VBA 6 Development Environment into your Application

DEMO

Object ModelObject Model

Page 29: Integrate the VBA 6 Development Environment into your Application

OutlineOutline

Key benefits of VBAKey benefits of VBA Preparing for VBA IntegrationPreparing for VBA Integration Integrating VBAIntegrating VBA

What is APCWhat is APC VBA Integration ArchitectureVBA Integration Architecture Phases of VBA IntegrationPhases of VBA Integration

Page 30: Integrate the VBA 6 Development Environment into your Application

Q: How do you integrate VBA?Q: How do you integrate VBA?

Integrating VBAIntegrating VBA

?A: Use Microsoft APC.A: Use Microsoft APC.

Application Programmability Component

!UseAPC

Page 31: Integrate the VBA 6 Development Environment into your Application

What is APC?What is APC?

APC APC Application Programmability Application Programmability ComponentComponent

COM object with interfaces used to COM object with interfaces used to host VBA (IApc*)host VBA (IApc*)

Can be used from most COM Can be used from most COM consumers (VB, MFC, ATL, C++, consumers (VB, MFC, ATL, C++, Delphi, etc.)Delphi, etc.)

Page 32: Integrate the VBA 6 Development Environment into your Application

What is Required for Your What is Required for Your Application to use APC?Application to use APC?

Must be able to call COM interfacesMust be able to call COM interfaces Must sink COM source interfacesMust sink COM source interfaces If your application needs to show If your application needs to show

the VBA Editor…the VBA Editor… ……it must provide access to its it must provide access to its

message loopmessage loop

Page 33: Integrate the VBA 6 Development Environment into your Application

VBA Integration ArchitectureVBA Integration Architecture

APC COM Component (IApc)

Integration Code

Microsoft VBA (IVba*)

Core VBA Code

MFC C++ VB Delphi…

Application Code

APC/C++ (CApc*)

APC/MFCTemplate Code

Page 34: Integrate the VBA 6 Development Environment into your Application

ApcApc

APC Object Model (Simplified)APC Object Model (Simplified)

ProjectProject

Projects

ProjectItemProjectItem

ProjectItems

ControlControl

Controls

Code ModuleCode Module

Class ModuleClass Module

UserFormUserForm

Host ClassHost Class

Designer ItemDesigner Item

Host Project ItemHost Project Item

Object

Collection

Page 35: Integrate the VBA 6 Development Environment into your Application

Phase 1: Initial Steps

Phase 2: Projects

Phase 3: (Optional) Project Items

VBA Integration Tasks

Phase 4: (Optional) Controls

Sim

ple

Sim

ple

Mo

derate

Mo

derate

Co

mp

lex C

om

plex

STOPSTOP

STOPSTOP

STOPSTOP

Note: Advanced Features can be added to any completed VBA integration project.

Page 36: Integrate the VBA 6 Development Environment into your Application

Phase 1: Initial StepsPhase 1: Initial Steps Initializing APCInitializing APC

Create the APC HostCreate the APC Host Associate the Application ObjectAssociate the Application Object Manage windows and eventsManage windows and events Show the VBA IDEShow the VBA IDE

Page 37: Integrate the VBA 6 Development Environment into your Application

Phase 1: Initial StepsPhase 1: Initial Steps Initializing APCInitializing APC

What is the Application object?What is the Application object? Merges methods & properties into Merges methods & properties into

namespacenamespace

Sub Main MsgBox “Hello” r = Application.Foo r = FooEnd Sub

MsgBox is a VBA built-in keywordFoo is a method of the Application object

Foo is merged into VBA’s global namespace and can be called without further qualification

Page 38: Integrate the VBA 6 Development Environment into your Application

Phase 1: Initial StepsPhase 1: Initial Steps Managing windows and eventsManaging windows and events

VBA IDE is a top-level windowVBA IDE is a top-level window Window parentingWindow parenting Tracking the active componentTracking the active component

Forward accelerators to active Forward accelerators to active componentcomponent

Re-entrant message loopRe-entrant message loop Isolate to a single set of routinesIsolate to a single set of routines

Page 39: Integrate the VBA 6 Development Environment into your Application

DEMO

Phase 1: Initial stepsPhase 1: Initial steps

Page 40: Integrate the VBA 6 Development Environment into your Application

Phase 2: ProjectsPhase 2: Projects

Project is the unit of persistenceProject is the unit of persistence Create, Save, Load a ProjectCreate, Save, Load a Project Execute codeExecute code An application can have multiple An application can have multiple

VBA projectsVBA projects

Page 41: Integrate the VBA 6 Development Environment into your Application

Phase 2: ProjectsPhase 2: ProjectsPersistencePersistence Requires OLE structured storage Requires OLE structured storage

(IStorage)(IStorage) Disk-based Disk-based

In your document fileIn your document file In standalone fileIn standalone file

In-memoryIn-memory Stored in a database as a BLOBStored in a database as a BLOB

Must be transactedMust be transacted IApcProject supports IPersistStorageIApcProject supports IPersistStorage For VB Developers, APC supports:For VB Developers, APC supports:

Storage ObjectStorage Object Stream ObjectStream Object

Page 42: Integrate the VBA 6 Development Environment into your Application

Phase 2: ProjectsPhase 2: ProjectsExecuting VBA codeExecuting VBA code

Named macros -- use the Run methodNamed macros -- use the Run methodTheProject.Run "ThisDocument", "Main"TheProject.Run "ThisDocument", "Main"

Available for ProjectItem, Procedure, Available for ProjectItem, Procedure, and Projectand Project

IApcProjectItem::RunIApcProjectItem::Run

IApcProcedure::RunIApcProcedure::Run

IApcProject::RunIApcProject::Run

Macros dialog...Macros dialog...Dim TheScopes As MSAPC.ScopesDim TheScopes As MSAPC.Scopes

Set TheScopes = TheProject.CreateScopesSet TheScopes = TheProject.CreateScopes

TheScopes.MacrosDialog.ShowTheScopes.MacrosDialog.Show

Page 43: Integrate the VBA 6 Development Environment into your Application

Phase 2: ProjectsPhase 2: ProjectsOther usesOther uses Code sharing / reuseCode sharing / reuse

Microsoft Word templates Microsoft Word templates (NORMAL.DOT)(NORMAL.DOT)

Global libraryGlobal library Custom event routingCustom event routing

Event goes first to main host project Event goes first to main host project itemitem

If event not handled, routes to If event not handled, routes to templatetemplate

Page 44: Integrate the VBA 6 Development Environment into your Application

DEMO

Phase 2: ProjectsPhase 2: Projects

Page 45: Integrate the VBA 6 Development Environment into your Application

Phase 3: Project ItemsPhase 3: Project Items

Used to expose an object in your Used to expose an object in your COM object model’s hierarchyCOM object model’s hierarchy

VBA user can write VBA code to VBA user can write VBA code to handle eventshandle events

VBA user can write code behindVBA user can write code behind

Page 46: Integrate the VBA 6 Development Environment into your Application

Phase 3: Project ItemsPhase 3: Project Items

Host project items are simply COM Host project items are simply COM objectsobjects Must derive from IDispatch and Must derive from IDispatch and

support IProvideClassInfosupport IProvideClassInfo Method’s parameters strongly typed Method’s parameters strongly typed

and namedand named Coclass exposes a source interface Coclass exposes a source interface

(events)(events)

Page 47: Integrate the VBA 6 Development Environment into your Application

Phase 4: ControlsPhase 4: Controls

VBA controls are simply COM VBA controls are simply COM objectsobjects

TypesTypes Built-in Built-in COM objects COM objects External External ActiveX controls (.OCX) ActiveX controls (.OCX)

Placed in the VBA hierarchy on a Placed in the VBA hierarchy on a host project itemhost project item

Control name merged into Control name merged into namespacenamespace

Page 48: Integrate the VBA 6 Development Environment into your Application

DEMO

Phases 3 & 4: Phases 3 & 4: Project Items and ControlsProject Items and Controls

Page 49: Integrate the VBA 6 Development Environment into your Application

Phase 1: Initial Steps

Phase 2: Projects

Phase 3: (Optional) Project Items

VBA Integration Phases: Summary

Phase 4: (Optional) Controls

Sim

ple

Sim

ple

Mo

derate

Mo

derate

Co

mp

lex C

om

plex

STOPSTOP

STOPSTOP

STOPSTOP

Note: Advanced Features can be added to any completed VBA integration project.

Page 50: Integrate the VBA 6 Development Environment into your Application

Advanced VBA FeaturesAdvanced VBA Features

VBA Extensibility Object ModelVBA Extensibility Object Model Digital SignaturesDigital Signatures COM Add-insCOM Add-ins ActiveX DesignersActiveX Designers

Page 51: Integrate the VBA 6 Development Environment into your Application

DEMO

Advanced FeaturesAdvanced Features

Page 52: Integrate the VBA 6 Development Environment into your Application

OutlineOutline

Key benefits of VBAKey benefits of VBA Preparing for VBA IntegrationPreparing for VBA Integration Integrating VBAIntegrating VBA

What is APCWhat is APC VBA Integration ArchitectureVBA Integration Architecture Phases of VBA IntegrationPhases of VBA Integration

Page 53: Integrate the VBA 6 Development Environment into your Application

For more information…For more information…

http://msdn.microsoft.com/vbahttp://msdn.microsoft.com/vba http://www.summsoft.com/http://www.summsoft.com/vbavba

Page 54: Integrate the VBA 6 Development Environment into your Application