Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 31,357 times

Contents

Related Categories

Using OLE Automation in VB - Creating the Application

S.S. Ahmed

Creating the Application

Follow the steps below to create the application:

Start a new EXE project. Select Microsoft Word 9.0 object library from the references dialog box (Project|References menu). Remember, you should have Word instance on your system. Add a new module to the project. In the module's general declarations section, add the following code:

Public objApp as New Word.application
Public objDoc as Object

Open the project's form and add four buttons to the form.
Buttons are:

  1. Launch
  2. Save
  3. Close
  4. Exit

Now double click the "Launch" button and add the following code:

Private sub cmdLaunch_click()

If Not(objdoc is nothing) then
    MsgBox "Application already running"
    Exit Sub
End if

'show the app
objapp.visible=true

'Add a document to the application

Set objdoc = objapp.Documents.Add()

'Write some text in the document

objdoc.content = "This is my first OLE application"

End Sub

Let's discuss the code. We check if the application is already running, if it's not then we display the application. We add a new document to the open word application and add some text to the application.

S.S. Ahmed is a senior IT Professional and works for a web and software development firm. Ahmed is a Microsoft Office SharePoint Server MVP. Ahmed specializes in creating database driven dynamic web sites. He has been working with SharePoint for the last 3-4 years. He develops customized SharePoint solutions. Ahmed likes to hop into other tools as well. Ahmed has used Project Server, InfoPath and BizTalk. Ahmed enjoys travelling and has been to many parts of the world. Web: www.walisystems.com Blog: www.sharepointblogs.com/ssa

Comments

  • How to open

    Posted by TunnelStream on 07 Oct 2004


    this is a great example of how to create a new document using OLE but how can I point to and open an existing document? I want to edit the text that your example had me save.

  • Awesome!

    Posted by computerg33k on 06 Aug 2004

    Works great! However in your close_cmd button you must comment out the objapp.quit() because vb.net claims it's ambiguous (which is why i put the me.close in there). Also, I read somewhere that we s...