Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Windows 2000 and MS-Word

Posted on 2002-06-24
8
Medium Priority
?
802 Views
Last Modified: 2012-06-27
How can I open a Word dokument from a Delphi application in Windows XP and 2000 with MS-Word 2000, 9.0.

Following procedure used with Windows 98 doesn't work:

  try
    WordApp := GetActiveOleObject('Word.Application');
  except on exception do
    WordApp := CreateOleObject('Word.Application');
  end;
 WordApp.wordbasic.fileopen('Dokument.doc');
 WordApp.Visible := True;
 WordApp.Wordbasic.EditBookmark(Name, , , , -1);
 WordApp.Wordbasic.insert(Edit1.text);
0
Comment
Question by:rainbowsoftware
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 1

Expert Comment

by:chengjian
ID: 7103522
Hi

You can try this:

to find out how to use OLE with Word, see Delphi example... You can find it normally in

    C:\Program Files\Borland\Delphi5\Demos\Activex\Oleauto\Word8

To read all the text of a document try the code shown below... If you want to add more functionality my best advice is to record a macro in Word and find out the macro code. I found this technique very useful when I want to port the code to delphi...

best regards
Manuel Lopez (lopem)

procedure InsertText(Pal : string);
//inserta text in Word
var
  Sel : Selection;
begin
 Sel := Form1.MsWord.Selection;
 Sel.TypeText(Pal);
end;

procedure MovePreviousWord;;

var
 MoveUnit : OleVariant;
 vCount   : OleVariant;
 Extended : OleVariant;
begin
 MoveUnit := wdWord;
 vCount := 1;
 Extended := unassigned;
 Form1.MsWord.Selection.MoveLeft(MoveUnit, vCount, Extended);
end;

procedure MoveNextWord;
//move cursor to next word
var
 MoveUnit : OleVariant;
 vCount   : OleVariant;
 Extended : OleVariant;
begin
 MoveUnit := wdWord;
 vCount := 1;
 Extended := unassigned;
 Form1.MsWord.Selection.MoveRight(MoveUnit, vCount, Extended);
end;

procedure ReadWord;
//read a word from Word doc
var
  Pal      : string;
  i        : integer;
begin
 ActRange := Form1.MsWord.Selection.Words.Item(1);
 Pal := ActRange;
end;

procedure CountAllWordOnDoc(var Cuenta: integer);
var
  Tot : OleVariant;
  Total : integer;
begin
 Tot := Form1.MsWord.ActiveDocument.Words.Count;  
 Total := Tot;
 Cuenta := Total;
end;

procedure CountWordsHighLighted(var Cuenta : integer);

var
  Tot : OleVariant;
  Total : integer;
begin
 Tot := Form1.MSWord.Selection.Words.Count;
 Cuenta := Tot;
end;

procedure HighLightWord;
//HighLight a word

var
 MoveUnit : OleVariant;
 vCount   : OleVariant;
 Extended : OleVariant;
begin
 MoveUnit := wdWord;
 vCount := 1;
 Extended := wdExtend;
 Form1.MsWord.Selection.MoveRight(MoveUnit, vCount, Extended);
end;


procedure HomeCursor;
//put cursor at the beginning of the document
var
  Unidad : OleVariant;
  Extended : OleVariant;
begin
 Unidad := wdStory;
 Extended := Unassigned;
 Form1.MsWord.Selection.HomeKey(Unidad,Extended);
end;





procedure TForm1.Button1Click(Sender: TObject);
//check if you can read word by word, from beginning to end of document...
//this test will change all word from lower to UPPER case...

var
  Pal      : string;
  i        : integer;
  Total    : integer;
begin
 HomeCursor;
 CountAllWordOnDoc(Total);
 for i := 1 to Total do
 begin
   ActRange := MsWord.Selection.Words.Item(1);
   if i <> 1 then HighLightWord
             else
             begin
               HomeCursor;
               HighLightWord;
             end;
   Pal := ActRange;
   Pal := UpperCase(Pal);
   //ShowMessage(Pal);
 end;
end;

0
 

Author Comment

by:rainbowsoftware
ID: 7103830
Manuel, thanks for your comment.
Your code doesn't work because ActRange and a lot more are not defined.
And the example in C:\Program Files\Borland\Delphi5\Demos\Activex\Oleauto\Word8 doesn't work because Word97.dcu is not found.
Could you please give me a hint.
Joern
0
 
LVL 3

Expert Comment

by:lopem
ID: 7104437
Hi rainbowsoftware...

Do you have a typical installation of Delphi 5? I found Word97.pas and Word97.dcu in

   c:\program files\Borland\Delphi5\Ocx\servers

Try to copy the code (see the first message) to the delphi msword demo. It should work. If still have problems please tell me.

best regards,
Manuel Lopez (lopem)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rainbowsoftware
ID: 7104556
I use Delphi 3 c/s.
But I found, that when placing the Word document in Windows Documents folder my original procedure works:

WordApp.wordbasic.fileopen('Dokument.doc');

But placing the document somewhere else and then write:

WordApp.wordbasic.fileopen('C:\NewFolder\Dokument.doc');

it doesn't work. I find this very strange.




0
 
LVL 3

Expert Comment

by:lopem
ID: 7104585
Hi again,

I dont know what is going on here... I checked my Delphi 3 c/s installation and found no OLE Word automation example. In fact, no OCX folder found.

So maybe if you put your complete code (at least the first part, uses, implementation, etc.), I can try to figure out what is happening...

best regards,
Manuel Lopez (lopem)
0
 
LVL 1

Accepted Solution

by:
chengjian earned 800 total points
ID: 7116337
Sorry , My example is for delphi 5.

You can use:
Component->Import ActiveX
Choose Microsoft Word...
It would install a word component on your ActiveX page by default.

Or use CreateOleObject() to create word object and use VBA...
0
 

Expert Comment

by:CleanupPing
ID: 9343168
rainbowsoftware:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9453545
rainbowsoftware,
No comment has been added lately (17 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to chengjian http:#7116337

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

609 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