Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with OLE question

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi. I'm developing an application that needs to work with embedded msWord docs. I'm not sure how to do this. What I need to do is to create a new(in fact several new) msword documents during the program run. I could open MSWord make the program write what I want there and then make the program save the file. But I need the ms word window embedded in one of my forms. I can use an OLE container control to store the ms word window, but how can I write to it? And I suppose I can't even save the file I've created in .doc format(only on .ole right?). So I really don't know wich is the best solution for this. Is there any way of opening MS Word on vb like CreateObject("word.application") and then embedding it on my form?
If anyone could help at all I'd appreciate it a lot.
 
First of all, I wouldn't use the OLE control if I didn't have to. Secondly ,when you say you want to write to it, do you mean programmatically, or do you want the user of your program to actually be able to type in it as if they were using Word itself?

If the latter, then it might be worth you looking under Project - Components, clicking the Insertable Objects tab and selecting Microsoft Word Document. I'll leave you to work out the rest. Note that if you use this option, you will gain most of Word's menus and functionality in your own program.

Otherwise, you can include the Microsoft Word Object Library (9.0 if you're using Office 2000) into Project - References and declare a word object in your code. Virtually anything you can do in Word, you can do using the object model exposed by Word. Start with something like

Dim wrdApp as Word.Application
Dim wrdDoc as Word.Document

set wrdApp = New Word.Application
set wrdDoc = wrdApp.Documents.Open(...filename...) ..etc.

To create a new document, you would use something like

wrdApp.Documents.Add(..various parameters...)


This is an EXTREMELY bare bones introduction, but you should be able to pick up a lot of what you need by playing around and using the Object Browser. Lastly, unless you need users to be able to edit the documents directly, I would recommend the last method.
 
Thanks for your reply.
At this point I won't need the users to input text. The solution you gave me I've already tryed, but that way the word window won't be embedded on my form. And I need the word window to be embedded on the form so that the users can actually see it.
The problem is that I suspect the only way to do this is to embed word on my form and if I do so would I be able to write text to it using Selection.TypeText Text:="Text here" or not? Since I've tryed and it doesn't work. I mean how can I run code on an OLE object I suppose it's different of running code on a ms word app using the later method you've told me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top