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
54
Embed
Integrate the VBA 6 Development Environment into your Application
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
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Integrate the VBA 6 Development Integrate the VBA 6 Development
Environment into your ApplicationEnvironment into your Application
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
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
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
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
Buy and CustomizeBuy and Customize
Competitive Advantage!
Lower Initial Cost
Fast Deployment
Infinite Flexibility
Your Code & Data
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
““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
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!
DEMO
An Application with VBAAn Application with VBA
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
““Visual Basic for Application Visual Basic for Application Extensibility”Extensibility”
Defined in vbe6ext.olbDefined in vbe6ext.olbCodeModuleCodeModuleCommandBarEventsCommandBarEventsVBProjectVBProjectVBComponentVBComponentReferencesReferences......
* 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.
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”
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
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
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
VBA Building Blocks
COM-Enable Your Application
Design and Implement an Object Model
Preparing for VBA Integration
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.
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
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
VBA Building Blocks
COM-Enable Your Application
Design and Implement an Object Model
Preparing for VBA Integration
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
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
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
DEMO
Object ModelObject Model
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
Q: How do you integrate VBA?Q: How do you integrate VBA?
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.)
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
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
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
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
DEMO
Phase 1: Initial stepsPhase 1: Initial steps
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
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: