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.

388 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

Private Sub cmdCreate_Click()<br />

Dim objWord As Object<br />

Set objWord = CreateObject(“Word.<strong>Basic</strong>”)<br />

objWord.FileNewDefault<br />

objWord.Insert “I can resist everything.”<br />

objWord.Wordleft<br />

objWord.Bold<br />

objWord.Insert “ except temptation”<br />

objWord.FilePrint ‘Make sure your printer is on<br />

objWord.FileSaveAs “QUOTE.DOC”<br />

objWord.FileClose Set<br />

objWord = Nothing<br />

End Sub<br />

[Run <strong>and</strong> click the comm<strong>and</strong> button. The printer will produce the following output.]<br />

I can resist everything except temptation.<br />

THE OLE CONTAINER CONTROL<br />

An OLE Container control provides a bridge to Windows applications, such as spreadsheets<br />

<strong>and</strong> word processors. For instance, it can hold an Excel spreadsheet or a Word document. The<br />

application can be either linked or embedded through the OLE Container control. With linking,<br />

a link is established to the data associated with the application <strong>and</strong> only a snapshot of the<br />

data is displayed. Other applications can access the object’s data <strong>and</strong> modify them. For example,<br />

if you link a text file to a <strong>Visual</strong> <strong>Basic</strong> application, the text file can be modified by any<br />

application linked to it. The modified version appears in all documents linked to this text.<br />

With embedding, all the application’s data are actually contained in the OLE Container control<br />

<strong>and</strong> no other application has access to the data.<br />

When you place an OLE Container control on a form, the dialog box in Figure 13-1<br />

appears. You can select an application from the list <strong>and</strong> then press the OK button (or doubleclick<br />

on the application) to insert it into the control. Alternately, you can click on the “Create<br />

from File” option button to produce the dialog box in Figure 13-2. From this second<br />

dialog box, you specify a file (such as a Word .DOC file or an Excel .XLS file) by typing it<br />

into the text box or clicking the Browse comm<strong>and</strong> button <strong>and</strong> selecting it from a st<strong>and</strong>ard file<br />

selection dialog box. After the file has been selected, you have the option of checking the<br />

Link check box before clicking on the OK button to insert the contents of the file into the<br />

OLE Container control.<br />

FIGURE 13-1 An Insert Object Dialog Box

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

Saved successfully!

Ooh no, something went wrong!