Wednesday, March 2, 2011

Hello, word!

OLE automation servers are a natural part of most major Microsoft applications such as Microsoft Office products and many other popular applications, which means you can control them from your application almost as if they were a part of your program.
For example, let's take Microsoft Word 95. As you can see, it'll only take a few lines of code to make it possible to insert text to Word documents from your application (don't forget to add "OLEAuto" unit to your "uses" statement):

procedure InsertTextToWord(
  sText : string );
var  W : Variant;
  { create an OLE object of           }
  { type Word.Basic                   }
  W := CreateOleObject( 'word.basic' );
  { call Word.Basic's Insert function }
  W.Insert( sText );
Using the above function, all you have to do is call it with the text you want to insert:
InsertTextToWord( 'hello, word!' );
To find out what other commands you can use to control Microsoft Word (for example) lookup its help for "WordBasic" -- the name of the macro language used to write custom applications for Word. To find out if your favorite application supports OLE automation, lookup its help for "OLE Automation."

Source :

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum