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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automating MSWord

Status
Not open for further replies.

Lukeage

Programmer
Mar 11, 2004
5
GB
I got such a great response from the last posting, that I've decided to stop trawling the internet for my answers, and apply straight to the experts again.

This time it's about opening word documents from within an application. The problem is that when MSWord opens, it's minimised on the toolbar. This is what I'm trying to achieve:

I have edit boxes on a form which display the details of a document within a database e.g. Name, Recipient, Date etc. I have a button on the toolbar which when pressed OPENS the document in MSWord. It's opening yeah sure, but it's minimized which is no good. Is there a better way to do this??? Ideally I'd prefer to display the document on a seperate form within the app so I don't have to use MSWord. Is this possible???

Thanks People
 
are you using ShellExecute?

if yes, the last parameter indicates how you want your window get open (minimized, maximized or normal)

Another way for doing this is using an OLE component

--- LastCyborg ---
 
Thanks for responding.

Well I'm not really sure how I should be doing it, but I've started with this code

WordApplication1->Visible = true;

AnsiString CurrentDocID = MainTable->FieldValue["Document ID"]; // Get the document ID from the Data Table. The PathLocation method will take out the characters I don't need to identify the filename.
AnsiString Location = Data.PathLocation(CurrentDocID); // Get the path and filename
WordDocument1->ConnectTo(WordApplication1->Documents->Open((OleVariant)Location));
WordDocument1->Activate();

I tried using an OleContainer this afternoon, but although it's less complicated, I'm having trouble making the object scrollable. I used the ScrollBy property and assigned 2 buttons to scroll up and down, but when it scrolls, it leaves a copy of the document in the original position.......tried everything from Repaint to Refresh, but I can't make it work. Am I doing this all wrong? I can't find a decent example of opening and closing a word document anywhere. Apparently Borland C++ Developers guide has all the answers about automating Word so I ordered a copy. Maybe you can help me in the right direction.

Thanks Bud
 
I have a program that opens a document in WORD, I never had a problem with it being minimized...I minimize my application first (MainForm), then I set the visible property of TWordApplication to true, and at that point, it brings up WORD...then when I call the 'ConnectTo' method, it opens my docuement...I never need to call the 'Activate' method.
Here is my code...

OleVariant
oleDocName;

oleDocName = "pathandname.doc;

MainForm->WindowState = wsMinimized;

WordApplication1->Visible = true;

WordDocument1->ConnectTo(WordApplication1->Documents->
Open(oleDocName));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top