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:
- Launch
- Save
- Close
- 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.
Comments