Solved

How can a Delphi program cut text from Word?

Posted on 1998-11-04
12
368 Views
Last Modified: 2010-05-18
How can I programmatically cut from and paste text to Word? By clicking a button, the Delphi program should check if there is an open Word document and then cut the text from Word to the clipboard. I know how to paste from the clipboard, but not how to use Word Basic.
When the text has been processed in my program, the user should paste it back to Word by clicking another button.
0
Comment
Question by:toreot
  • 5
  • 4
  • 3
12 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1345623
Go through OLE,

First read this document :

http://members.aol.com/_ht_a/charliecal/TechPapers/DelphiWord.htm

Then if you still got problems, ask them and/or look at freeware components/examples at torries library.

Regards, Zif.
0
 

Author Comment

by:toreot
ID: 1345624
I have already taken a quick look at this document, but this is much more than I need and I don't have the time for researching this. Could anybody just supply me with the necessary code snippets?
0
 

Author Comment

by:toreot
ID: 1345625
I need specific code showing how to order Word to cut the text from a document and also pasting text from the clipboard.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 4

Accepted Solution

by:
dwwang earned 150 total points
ID: 1345626
Hi, hope this code fragment will help:

When having a MSWord running, just write:

     MSWord:Variant;
     ...
     ...
     MSWord:=GetActiveOleObject('Word.Basic');
     MSWord.EditSelectAll;
     MsWord.EditCopy;
     Form1.richedit1.PasteFromClipBoard;

    When need to paste back:

     //     Form1.richedit1.copytoclipboard
     MSWord.EditSelectAll;
     MsWord.EditPaste;

    Also if you want to start MSWord automatically:

     MSWord:=CreateOleObject('Word.Basic');
     MsWord.Appshow;
     Msword.FileNew; or FileOpen('FileName')

0
 

Author Comment

by:toreot
ID: 1345627
Unfortunately  MSWord:=GetActiveOleObject('Word.Basic') stops with an with an error 'Operation not available'.  This happens on two machines with Word 7 installed.

Also I have a feeling that this code won't work with Office 97. Is that correct?
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1345628
I don't think so, I have word97 installed on my machine when building the example using this method. Are you sure MSWord is running when you call GetActiveOleObject('Word.Basic')? Or else you shold call CreateOleObject('Word.Basic').
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1345629
GetActiveOleObject can only be used if the program (in this case, Word) is already opened. Use CreateOleObject when you want to start a program (word in this case). Mostly we combine these two :

First use GetActiveOleObject. If this raises an OLE exception, then use CreateOleObject to start Word. If this raises an exception, than word isn't installed (probably).
0
 

Author Comment

by:toreot
ID: 1345630
Sorry, when I have Word 7 open (Norwegian version, is that important?) I still get the EOleSysError.
Using CreateOleObject  nothing seems to happen, but perhaps this instance of Word isn't visible?
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1345631
If you use MSWord:=CreateOleObject('Word.Basic'); you also need the MsWord.Appshow; to show the application(see my answer above.)

I realized that there are some problems when you use localized MSWord, because name of all the objects and methods of word basic could be localized. Maybe you can check out the help of your word to find the proper object/method name to use. see the "autoctrl" demo in Delphi 3 to find how to deal with this situation, it can process 3 languages.

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1345632
dwwang, it is not nessecary to make msword visible. I should also work without making it visible.
toreot, if you only make some time to read the examples in that article, then you normally should get away with it.

0
 
LVL 4

Expert Comment

by:dwwang
ID: 1345633
Hi, Zif:
Yes, I know there's no need to show the application, just for answering toreot's question. :)

Regards,
Wang
0
 

Author Comment

by:toreot
ID: 1345634
Sorry about the delay. GetActiveOleObject('Word.Basic') should work for the Norwegian version of Word, but doesn't. However, using CreateOleObject('Word.Basic') and translating the WordBasic function names to Norwegian, dwwang's code works even if Word is already open, so I award him the points.

It would be nice to know, however, why GetActiveOleObject('Word.Basic') raises the EOleSysError 'Operation not available' (translated from Norwegian).
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Strange code, can use it, but i cant figure out what it does. 3 60
delphi prevent click fast 2 219
CheckListBox usage 3 59
Firemonkey allowing RTL on android 6 33
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question