1 / 54

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.

guido
Télécharger la présentation

Integrate the VBA 6 Development Environment into your Application

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Integrate the VBA 6 Development Environment into your Application Rebecca RinnerSenior Software EngineerSummit Software Company 4-307

  2. Outline • Key benefits of VBA • Preparing for VBA Integration • Integrating VBA • What is APC • VBA Integration Architecture • Phases of VBA Integration

  3. Outline • Key benefits of VBA • Preparing for VBA Integration • Integrating VBA • What is APC • VBA Integration Architecture • Phases of VBA Integration

  4. Enable customers to tailor your product to their specific needs Customize Deliver the power of Visual Basic to leverage the 3+ million VB developers Enable customers to create entire line of business solutions Integrate Leverage Visual Basic for Applications The premier development technology found in applications that enables your customers to:

  5. Buy Build Buy vs. Build Pros Lower Initial Cost Fast Deployment Cons Not Flexible No Advantage Pros Infinite Flexibility Your Code & Data Cons High Risk High Cost

  6. Buy and Customize Infinite Flexibility Lower Initial Cost Fast Deployment Your Code & Data Competitive Advantage!

  7. Flexibility • Your application becomes a platform • Write portions of your application in VBA • Change features after you ship • Add features after you ship • Eliminate one-off feature requests • Create a 3rd party community

  8. “Got VBA?” • VBA throughout Office 2000 • Outlook, FrontPage • 100+ shipping applications • New announcements every week

  9. Types of Applications • Traditional “thick client” • Multi-threaded applications • Multi-threaded designer • VBA in the Middle-tier • Allows customizable business objects • Duwamish sample on MSDN • Thin client Check out the VBA Pavilion!

  10. An Application with VBA DEMO

  11. Outline • Key benefits of VBA • Preparing for VBA Integration • Integrating VBA • What is APC • VBA Integration Architecture • Phases of VBA Integration

  12. Preparing for VBA Integration VBA Building Blocks COM-Enable Your Application Design and Implement an Object Model

  13. VBA Building Blocks… • Visual Basic Editor (VBE) • Project Explorer • Code Editor • Immediate Window • Properties Window • Locals, Watch, ... • VBE Object model • “Visual Basic for Application Extensibility” • Defined in vbe6ext.olb CodeModuleCommandBarEventsVBProjectVBComponentReferences...

  14. VBA Building Blocks... Project Hierarchy VBA Project Project Items Host project Items Controls* UserForms Code modules Class modules Host classes** Designers** * 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.

  15. VBA Building Blocks... • VBA Project • Unit of persistence • Uses IStorage to load/save • Often, a 1:1 association with documents • An application can have multiple VBA projects • Contains all code in “Project Items”

  16. VBA Building Blocks... • Project Items • Host project items • Simply COM objects • Expose events to VBA • Code “behind” (using COM aggregation) • Can have controls • Host Classes • Just like host project items, except that you can have multiple instances of them

  17. VBA Building Blocks... • Project items... • Code module • Contain VBA code only • Global • Class module • Creatable VBA classes • UserForms and Other Designers • UserForms (built-in) • Can be used to build UI for your application • VB6 Designers

  18. VBA Building Blocks... • Code Execution • Macros dialog box • Named macros executedin response to UI • Toolbar, menu selection, keystroke • Can pass parameters • Events • Code behind

  19. Preparing for VBA Integration VBA Building Blocks COM-Enable Your Application Design and Implement an Object Model

  20. COM-Enable Your Application • Follow the COM Specification • Adopt the COM Philosophy • Use COM as the Binary Standard for Application Components • For MFC applications, use ATL for COM support.

  21. APC VBA COM-Enable Your Application... • You don’t have to rewrite your application • Use “peer” objects Application C++ or MFCclasses “Peer”COM Objects

  22. APC VBA COM-Enable Your Application... • VB Applications are COM “friendly” • COM object model exposed as VB classes Application VB Classes

  23. Preparing for VBA Integration VBA Building Blocks COM-Enable Your Application Design and Implement an Object Model

  24. Design and Implementan Object Model • Definition: An Object Model is the set of objects, methods, and properties your application exposes for programmability • Required for VBA integration

  25. Why Expose an Object Model? • Allow your application to be part of bigger solutions • Can be driven by a wide variety of tools (VBA, VB, VC++, Delphi, and others) • Create a 3rd party community supporting your product • Required for VBA integration

  26. Object Model Design Tips • Use standard constructs and behavior • Users will already know it. • Users will intuitively understand it. • VBA will not choke on it. • Events provide • Respond to user actions • Respond to detected conditions • Hook application internals • See the Summit white paper

  27. Object Model DEMO

  28. Outline • Key benefits of VBA • Preparing for VBA Integration • Integrating VBA • What is APC • VBA Integration Architecture • Phases of VBA Integration

  29. A: Use Microsoft APC.Application Programmability Component ! ? Q: How do you integrate VBA? Integrating VBA UseAPC

  30. What is APC? • APC Application Programmability Component • COM object with interfaces used to host VBA (IApc*) • Can be used from most COM consumers (VB, MFC, ATL, C++, Delphi, etc.)

  31. What is Required for Your Application to use APC? • Must be able to call COM interfaces • Must sink COM source interfaces • If your application needs to show the VBA Editor… • …it must provide access to its message loop

  32. MFC C++ VB Delphi… Template Code APC/MFC Application Code Integration Code APC/C++ (CApc*) Core VBA Code APC COM Component (IApc) Microsoft VBA (IVba*) VBA Integration Architecture

  33. Project Projects ProjectItem ProjectItems Control Controls APC Object Model (Simplified) Object Apc Collection Host Project Item Code Module Class Module Designer Item UserForm Host Class

  34. Phase 1: Initial Steps Phase 2: Projects STOP Phase 3: (Optional) Project Items STOP Phase 4: (Optional) Controls STOP VBA Integration Tasks Simple Moderate Complex Note: Advanced Features can be added to any completed VBA integration project.

  35. Phase 1: Initial StepsInitializing APC • Create the APC Host • Associate the Application Object • Manage windows and events • Show the VBA IDE

  36. Phase 1: Initial StepsInitializing APC • What is the Application object? • Merges methods & properties into namespace Sub Main MsgBox “Hello” r = Application.Foo r = FooEnd Sub MsgBox is a VBA built-in keyword Foo is a method of the Application object Foo is merged into VBA’s global namespace and can be called without further qualification

  37. Phase 1: Initial StepsManaging windows and events • VBA IDE is a top-level window • Window parenting • Tracking the active component • Forward accelerators to active component • Re-entrant message loop • Isolate to a single set of routines

  38. Phase 1: Initial steps DEMO

  39. Phase 2: Projects • Project is the unit of persistence • Create, Save, Load a Project • Execute code • An application can have multiple VBA projects

  40. Phase 2: ProjectsPersistence • Requires OLE structured storage (IStorage) • Disk-based • In your document file • In standalone file • In-memory • Stored in a database as a BLOB • Must be transacted • IApcProject supports IPersistStorage • For VB Developers, APC supports: • Storage Object • Stream Object

  41. Phase 2: ProjectsExecuting VBA code • Named macros -- use the Run method TheProject.Run "ThisDocument", "Main" • Available for ProjectItem, Procedure, and Project IApcProjectItem::Run IApcProcedure::Run IApcProject::Run • Macros dialog... Dim TheScopes As MSAPC.Scopes Set TheScopes = TheProject.CreateScopes TheScopes.MacrosDialog.Show

  42. Phase 2: ProjectsOther uses • Code sharing / reuse • Microsoft Word templates (NORMAL.DOT) • Global library • Custom event routing • Event goes first to main host project item • If event not handled, routes to template

  43. Phase 2: Projects DEMO

  44. Phase 3: Project Items • Used to expose an object in your COM object model’s hierarchy • VBA user can write VBA code to handle events • VBA user can write code behind

  45. Phase 3: Project Items • Host project items are simply COM objects • Must derive from IDispatch and support IProvideClassInfo • Method’s parameters strongly typed and named • Coclass exposes a source interface (events)

  46. Phase 4: Controls • VBA controls are simply COM objects • Types • Built-in  COM objects • External  ActiveX controls (.OCX) • Placed in the VBA hierarchy on a host project item • Control name merged into namespace

  47. Phases 3 & 4: Project Items and Controls DEMO

  48. VBA Integration Phases: Summary Phase 1: Initial Steps Simple Moderate Phase 2: Projects Complex STOP Phase 3: (Optional) Project Items STOP Phase 4: (Optional) Controls STOP Note: Advanced Features can be added to any completed VBA integration project.

  49. Advanced VBA Features • VBA Extensibility Object Model • Digital Signatures • COM Add-ins • ActiveX Designers

More Related