19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Notice that the document in the OLE rectangle is the original document, not the<br />

modified version. <strong>Visual</strong> <strong>Basic</strong> maintains an image of this original document in<br />

the program to display at run time if it is unable to display the latest version of<br />

the data (document).<br />

8. Run the program.<br />

The document is still the original version.<br />

9. Double-click on the OLE rectangle to invoke Word.<br />

Notice that the document displayed is the modified version.<br />

10. Exit back to <strong>Visual</strong> <strong>Basic</strong> <strong>and</strong> then end the <strong>Visual</strong> <strong>Basic</strong> program.<br />

11. Double-click on the form <strong>and</strong> add the code<br />

Ole1.Action = 6 ‘Update OLE image<br />

to the Form_Load event procedure.<br />

12. Run the program.<br />

Notice that <strong>Visual</strong> <strong>Basic</strong> has updated the document to the last version saved<br />

while in Word even though you have not yet accessed Word by double-clicking.<br />

COMMENTS<br />

1. OLE requires a powerful computer to operate at a reasonable speed.<br />

2. An embedded application in the container OLE1 can be made into an OLE<br />

Automation object by a pair of statements of the form<br />

Dim objVar As Object<br />

Set objVar = OLE1.Object<br />

3. After an Excel spreadsheet has been opened as an object, data can be assigned<br />

to <strong>and</strong> read from a single cell with statements such as<br />

objExcel.Application.Cells(4, 2).Value = “49”<br />

num = objExcel.Application.Cells(1, 3).Value<br />

These statements can be replaced by the following statements that use the st<strong>and</strong>ard<br />

spreadsheet notation for cells.<br />

objExcel.Application.Range(“B4”).Value = “49”<br />

num = objExcel.Application.Range(“C1”).Value<br />

4. A linked or embedded application can be activated by double-clicking on the<br />

OLE container. They can also be activated with the code<br />

OLE1.Action = 7<br />

<strong>and</strong> deactivated with the code<br />

OLE1.Action = 9<br />

5. The OLE Automation function GetObject, which is similar to CreateObject, can<br />

be used to access existing Excel spreadsheets. For instance, if a worksheet<br />

resides in the root directory on a diskette in drive A <strong>and</strong> has the name EXPENS-<br />

ES.XLS, then the spreadsheet can be accessed with the pair of statements<br />

Dim objExcel As Object<br />

Set objExcel = GetObject(“A:\EXPENSES.XLS”)<br />

6. Some other Word statements for use in OLE Automation are<br />

OLE 391

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!