Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 6 Programming with Office 97

Similar presentations


Presentation on theme: "Chapter 6 Programming with Office 97"— Presentation transcript:

1 Chapter 6 Programming with Office 97
Exploring Microsoft Visual Basic 6.0 6 Chapter 6 Programming with Office 97 The OLE Container Control and Automation By Carlotta Eaton Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. Copyright 1999 Prentice-Hall, Inc.

2 Copyright 1999 Prentice-Hall, Inc.
Objectives... 1. Explain Windows data sharing technologies such as clipboard, DDE, OLE and ActiveX. 2. Explain OLE; differentiate between an embedded object and a linked one. 3. Understand old and new terms for data-sharing technologies. Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

3 Chapter 6 - Programming with Office 97
Exploring Microsoft Visual Basic 6.0 Objectives 4. Use the OLE container control to embed or link an object. 5. Explain and use automation to create an application with components and functions available in Office 97 applications. Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc. Copyright 1999 Prentice-Hall, Inc.

4 Sharing Data between Applications
Clipboard Dynamic Data Exchange (DDE) Object Linking and Embedding (OLE) ActiveX Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

5 Copyright 1999 Prentice-Hall, Inc.
Clipboard First sharing method available with Windows Holding area where information can be copies and transferred Limited to a single object No way to automatically update data placed on clipboard Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

6 Dynamic Data Exchange (DDE)
Introduced in later Windows versions Applications can exchange data and commands while running A connection is made between the two applications Data can be automatically updated and transferred Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

7 Object Linking and Embedding
Introduced with Windows 3.1 More sophisticated technique than DDE to achieve same results Not limited to data and commands Method of combining data created by different applications Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

8 Copyright 1999 Prentice-Hall, Inc.
How OLE Works Embedding Linking Server Application Server Application Object copied Object linked Container Application Container Application Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

9 Copyright 1999 Prentice-Hall, Inc.
How OLE Works Embedding Linking If you modify the source object Server Application Server Application Link updates and retrieves current source object Embedded (copied) object does not change Destination Application Destination Application Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

10 Copyright 1999 Prentice-Hall, Inc.
OLE Terminology Compound document - document containing elements from multiple applications Embedded object - original object is copied and stored in the compound document Linked object - original object remains stored in original file and is linked to container document Container document - the compound document that contains elements from multiple applications Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

11 New and Old OLE Terminology
Container application previously called client or destination application that receives the object OLE Container control previously called OLE client control permits an OLE object to be added to a form Server application previously called source application that creates the object Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

12 Copyright 1999 Prentice-Hall, Inc.
ActiveX Technology ActiveX servers or ActiveX components previously called OLE servers or OLE automation servers originally ActiveX referred to software components that were created for the Web using OLE technology ActiveX now refers to a wide range of communication techniques where applications make their capabilities available to other applications Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

13 The OLE Container Control
Permits an OLE object to be added to a form Insert an OLE Object at design time Place an OLE container control on a form The Insert Object dialog box displays (see next slide) Insert an OLE Object at run time Click the Cancel command button on the Insert Object dialog box, and add code to insert the object later In-place activation Allows direct editing of the OLE object placed in the OLE container control Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

14 OLE Container Control Insert Object dialog box
Create a new object Insert an object at runtime Create a object from an existing file Display only an Icon Link an existing object Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

15 OLE Container Demonstration
Hands-On Exercise 1 Open and save the OLE Starter project Add the OLE Container control to the Embed form, Paste form, Link, and Icon forms Modify the source worksheet Test the embedded objects Test the linked objects Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

16 Copyright 1999 Prentice-Hall, Inc.
Automation Visual Basic technology that allows us to use code and objects from other Windows applications in our applications Previously called OLE Automation Referenced application (such as Word or Excel) must be available on the end user’s computer Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

17 Available References References dialog box
First, determine which automation objects are available using the References dialog box Word 97 Object Library Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

18 Copyright 1999 Prentice-Hall, Inc.
The Object Browser Next, find the function or method to use for spell check capability Check Spelling available here Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

19 Viewing Object Hierarchies
Use help to display all the available Microsoft Word objects Spelling Suggestions available here Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

20 Declaring an Automation Object
First, declare the object Late Binding when the object is generically declared the slowest form of binding Early Binding when the object is specifically declared such as Word, Excel, worksheet etc. usually run fastest Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

21 The CreateObject Function
Next, create a new automation object Set objectname = CreateObject(Application.Object) Where Set is the required command objectname is the name of the automation object CreateObject is the required function Application is the class name of the application Object is the type of object Examples: Set xlsSheet = CreateObject(“Excel.Sheet”) Set wdDoc = CreateObject(“Word.Document”) Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

22 The GetObject Function
To create a new automation object from an existing file Set objectname = GetObject(filename) Where Set is the required command objectname is the name of the automation object GetObject is the required function filename is the location of the existing file Examples: Set xlsSheet = GetObject(“c:\data\finance.xls”) Set wdDoc = GetObject(“c:\docs\letter.doc”) Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

23 The App.Path Global Variable
To get a file from the current folder where your Visual Basic application is running, use the App.Path global variable Examples: Set xlsSheet = GetObject(App.Path & _ “finance.xls”) Set wdDoc = GetObject(App.Path & _ “letter.doc”) Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

24 Release an Automation Object
Remove the object from memory when we are finished with an object with the Set statement and Nothing keyword Set objectname = Nothing Where Set is the required command objectname is the name of the automation object Nothing is the required keyword Examples: Set xlsSheet = Nothing Set wdDoc = Nothing Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

25 The Spell Pad Project using Automation
Hands-On Exercise 2 Create the Spell Pad form Add menus and set the form properties Add code to display the form Test the form code Add the Word Library reference Add code and test spell check Add code and test grammar check Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

26 Copyright 1999 Prentice-Hall, Inc.
Saving OLE Object Save changes to an OLE object using the SaveToFile method of the OLE container control Objectname.SaveToFile filenumber Where objectname is the name of the automation object SaveToFile is the required method filenumber is the number of the file and must correspond to an open binary file Examples: NextFile = FreeFile oleObject.SaveToFile NextFile Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

27 The Mortgage Minder Project
Mortgage Minder Excel Workbook Setup worksheet contains setup values and assumptions Term Option worksheet calculates payments for several term options Loan Comparisons worksheet calculates loans with varying interest rates Schedule worksheet calculates amortization schedule for loan Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

28 The Mortgage Minder Project
Mortgage Minder Forms Splash form Main form More Info form Comparisons form Term Options form Schedule form Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

29 Copyright 1999 Prentice-Hall, Inc.
The Splash form Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

30 Copyright 1999 Prentice-Hall, Inc.
The Main form Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

31 Copyright 1999 Prentice-Hall, Inc.
The More Info form Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

32 Copyright 1999 Prentice-Hall, Inc.
The Term Options form Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

33 Copyright 1999 Prentice-Hall, Inc.
The Comparisons form Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

34 Copyright 1999 Prentice-Hall, Inc.
The Schedule form Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

35 The Mortgage Minder Project
Hands-On Exercise 3 Open and save the project, module and form files Test the existing forms Modify and test the Options form Modify and test the Comparisons form Modify and test the Schedule form Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

36 Copyright 1999 Prentice-Hall, Inc.
Summary ... Utilize code contained in other applications All Office 97 applications are ActiveX servers Clipboard, DDE, OLE, and ActiveX progression of data sharing technologies Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

37 Copyright 1999 Prentice-Hall, Inc.
Summary Introduction to OLE (Object Linking and Embedding) Automation is a powerful tool that allows us to work with programmable data objects Created Spell Pad and Mortgage Minder applications Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

38 Practice with Visual Basic
1. Using the OLE Container Control 2. In the Kitchen with Automation 3. Sample Word Automation 4. OLE Container Sample Application 5. More Spell Check 6. OLE and PowerPoint Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.

39 Copyright 1999 Prentice-Hall, Inc.
Case Studies Programming with PowerPoint Careers in Visual Basic Programming a Handheld PC Programming with Excel Exploring MS Visual Basic 6 Copyright 1999 Prentice-Hall, Inc.


Download ppt "Chapter 6 Programming with Office 97"

Similar presentations


Ads by Google