Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Integrate the VBA 6 Development Environment into your Application Rebecca Rinner Senior Software Engineer Summit Software Company 4-307."— Presentation transcript:

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

2

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

4 Outline Key benefits of VBA Key benefits of VBA Preparing for VBA Integration Preparing for VBA Integration Integrating VBA Integrating VBA What is APC What is APC VBA Integration Architecture VBA Integration Architecture Phases of VBA Integration Phases of VBA Integration

5 Visual Basic for Applications The premier development technology found in applications that enables your customers to: Customize Enable customers to tailor your product 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

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

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

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

9 Got VBA? VBA throughout Office 2000 VBA throughout Office 2000 Outlook, FrontPage Outlook, FrontPage 100+ shipping applications 100+ shipping applications New announcements New announcements every week

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

11 DEMO An Application with VBA

12 Outline Key benefits of VBA Key benefits of VBA Preparing for VBA Integration Preparing for VBA Integration Integrating VBA Integrating VBA What is APC What is APC VBA Integration Architecture VBA Integration Architecture Phases of VBA Integration Phases of VBA Integration

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

14 VBA Building Blocks… Visual Basic Editor (VBE) Visual Basic Editor (VBE) Project Explorer Project Explorer Code Editor Code Editor Immediate Window Immediate Window Properties Window Properties Window Locals, Watch,... Locals, Watch,... VBE Object model VBE Object model Visual Basic for Application Extensibility Visual Basic for Application Extensibility Defined in vbe6ext.olb Defined in vbe6ext.olb CodeModule CommandBarEvents VBProject VBComponent References...

15 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.

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

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

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

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

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

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

22 COM-Enable Your Application... Application Peer COM Objects You dont have to rewrite your application You dont have to rewrite your application Use peer objects Use peer objects C++ or MFC classes APC VBA

23 COM-Enable Your Application... Application VB Classes VB Applications are COM friendly COM object model exposed as VB classes APC VBA

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

25 Design and Implement an Object Model Definition: An Object Model is the set of objects, methods, and properties your application exposes for programmability Definition: An Object Model is the set of objects, methods, and properties your application exposes for programmability Required for VBA integration Required for VBA integration

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

27 Object 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 provide Events provide Respond to user actions Respond to user actions Respond to detected conditions Respond to detected conditions Hook application internals Hook application internals See the Summit white paper See the Summit white paper

28 DEMO Object Model

29 Outline Key benefits of VBA Key benefits of VBA Preparing for VBA Integration Preparing for VBA Integration Integrating VBA Integrating VBA What is APC What is APC VBA Integration Architecture VBA Integration Architecture Phases of VBA Integration Phases of VBA Integration

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

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

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

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

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

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

36 Phase 1: Initial Steps Initializing APC Create the APC Host Create the APC Host Associate the Application Object Associate the Application Object Manage windows and events Manage windows and events Show the VBA IDE Show the VBA IDE

37 Phase 1: Initial Steps Initializing APC What is the Application object? What is the Application object? Merges methods & properties into namespace Merges methods & properties into namespace Sub Main MsgBox Hello r = Application.Foo r = Foo End Sub MsgBox is a VBA built-in keyword Foo is a method of the Application object Foo is merged into VBAs global namespace and can be called without further qualification

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

39 DEMO Phase 1: Initial steps

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

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

42 Phase 2: Projects Executing VBA code Named macros -- use the Run method Named macros -- use the Run method TheProject.Run "ThisDocument", "Main" Available for ProjectItem, Procedure, and Project Available for ProjectItem, Procedure, and ProjectIApcProjectItem::RunIApcProcedure::RunIApcProject::Run Macros dialog... Macros dialog... Dim TheScopes As MSAPC.Scopes Set TheScopes = TheProject.CreateScopes TheScopes.MacrosDialog.Show

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

44 DEMO Phase 2: Projects

45 Phase 3: Project Items Used to expose an object in your COM object models hierarchy Used to expose an object in your COM object models hierarchy VBA user can write VBA code to handle events VBA user can write VBA code to handle events VBA user can write code behind VBA user can write code behind

46 Phase 3: Project Items Host project items are simply COM objects Host project items are simply COM objects Must derive from IDispatch and support IProvideClassInfo Must derive from IDispatch and support IProvideClassInfo Methods parameters strongly typed and named Methods parameters strongly typed and named Coclass exposes a source interface (events) Coclass exposes a source interface (events)

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

48 DEMO Phases 3 & 4: Project Items and Controls

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

50 Advanced VBA Features VBA Extensibility Object Model VBA Extensibility Object Model Digital Signatures Digital Signatures COM Add-ins COM Add-ins ActiveX Designers ActiveX Designers

51 DEMO Advanced Features

52 Outline Key benefits of VBA Key benefits of VBA Preparing for VBA Integration Preparing for VBA Integration Integrating VBA Integrating VBA What is APC What is APC VBA Integration Architecture VBA Integration Architecture Phases of VBA Integration Phases of VBA Integration

53 For more information… http://msdn.microsoft.com/vba http://msdn.microsoft.com/vba http://msdn.microsoft.com/vba http://www.summsoft.com/vba http://www.summsoft.com/vba http://www.summsoft.com/vba

54


Download ppt "Integrate the VBA 6 Development Environment into your Application Rebecca Rinner Senior Software Engineer Summit Software Company 4-307."

Similar presentations


Ads by Google