Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 11-16-2012, 09:27 PM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 217
Default Add shape to a word document

I currently have a word document loaded through OLE automation, however I need to add a shape to circle some text. I know in VB i can do the following:

Code:
Dim Oval = WordDoc.Shapes.AddShape(9,200,200,100,100)
Oval.Fill.Visible = 0
Oval.Line.ForeColor.RGB = 255
Oval.Line.Weight = 2
How do I perform this in Delphi?
  #2  
Old 11-17-2012, 11:22 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default

It should be like this:


Code:
uses
  ComObj;
..........................................................
..........................................................
var 
    Oval : OLEVariant;
begin
    Oval := WordDoc.Shapes.AddShape(9,200,200,100,100);
    Oval.Fill.Visible := 0;
    Oval.Line.ForeColor.RGB := 255:
    Oval.Line.Weight := 2;
__________________
Regards,
Abdulaziz Jasser
  #3  
Old 11-17-2012, 03:53 PM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 217
Default

Thanks Jasser, but i get the following error:

Method 'Shapes' not supported by automation object.
  #4  
Old 11-17-2012, 05:21 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default

If its works for VB then it should work for Delphi (Simply becuase it is OLE code)!!! Can you show me some complete code?
__________________
Regards,
Abdulaziz Jasser

Last edited by Jasser; 11-17-2012 at 07:08 PM.
  #5  
Old 11-18-2012, 02:57 PM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 217
Default

Here is my code:
[code]
var
WordApp, WordRange, SearchString, ReplaceString:OLEVariant;
WordDoc:string;
t:integer;
oval:OLEVariant;

begin
WordDoc:=FileName;
WordApp:=CreateOLEObject('Word.Application');
WordApp.Visible:=true;
WordApp.Documents.open('"'+WordDoc+'"');
WordRange:=WordApp.ActiveDocument.Content;

try
Oval := WordApp.Shapes.AddShape(9,200,200,100,100);
Oval.Fill.Visible := 0;
Oval.Line.ForeColor.RGB := 255;
Oval.Line.Weight := 2;
except
WordApp.quit;
end;
WordApp.visible:=true;
WordApp.quit;
[/code/
  #6  
Old 11-18-2012, 05:44 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default

I have made some changes to make your code more clean:


Code:
var
          WordApp, WordRange, SearchString, ReplaceString:OLEVariant;
          WordDoc :string;
          t:integer;
          oval:OLEVariant;
begin
          WordDoc := WordDoc;
          WordApp := CreateOLEObject('Word.Application');
          WordApp.Visible:= True;
          WordApp.Documents.Open('"'+WordDoc+'"');
          WordRange := WordApp.ActiveDocument.Content;

          try
              Oval := WordApp.Documents.Item(1).Shapes.AddShape(9,200,200,500,500);
              Oval.Fill.Visible := 0;
              Oval.Line.ForeColor.RGB := 255;
              Oval.Line.Weight := 2;

              //If you want to save the changes without seeing the SAVE dialog then add the next line.
              WordApp.ActiveDocument.Close(wdSaveChanges, EmptyParam, EmptyParam);
              WordApp.Quit;
          except
              WordApp.Quit;
          end;
__________________
Regards,
Abdulaziz Jasser

Last edited by Jasser; 11-18-2012 at 05:57 PM.
  #7  
Old 11-18-2012, 05:58 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,060
Default

For more OLE with Word and Delphi see http://www.djpate.freeserve.co.uk/AutoWord.htm
__________________
Regards,
Abdulaziz Jasser
  #8  
Old 11-18-2012, 06:21 PM
Zaaka Zaaka is offline
Senior Member
 
Join Date: Aug 2002
Location: Teesside, UK
Posts: 217
Default

Thanks Jasser, I have now got it working, thanks for all your help
Closed Thread

Tags
add, automation, delphi, shape, word

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 03:40 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.