[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Word Document methods

Posted on 2002-07-14
Medium Priority
Last Modified: 2010-04-04

After I open with word a basic document i wish to add one by one pictures (or document) after the base document text.
The problem is that the pictures i add are always inserting before the original text (top document), and not on the bottom of the document.

I Also want that every picture will stretch as much as possible to the word document width.

how can i fix it ? ?

Here is my code
    WordApp := GetActiveOleObject('Word.Application');
  except on exception do
      WordApp := CreateOleObject('Word.Application');
  WordApp.ActiveDocument.Shapes.AddPicture('C:\Backup\First.tif', True,True);
  WordApp.ActiveDocument.Shapes.AddPicture('C:\Backup\Second.tif', True,True);

i.e. the document shoud be in that order
1) Original text
2) picture #1 (how to stretch  ?)
2) picture #2
Its look like the cursor is not on the right location (on the top and not on the buttom)

I use delphi 5Pro

thank u
Question by:asi
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

Expert Comment

ID: 7152749
Hi, Asi

Your code:

  WordApp.ActiveDocument.Shapes.AddPicture('C:\Backup\First.tif', True,True);
  WordApp.ActiveDocument.Shapes.AddPicture('C:\Backup\Second.tif', True,True);

didnt work for me. In fact, when Im typing the line you gave the system ask for these parameters:

const FileName: WideString; var LinkToFile: OleVariant; var SaveWithDocument: OleVariant;
var Left: OleVariant; Top : OleVariant; var Width: Olevariant; var Height: OleVariant; var Anchor: Olevariant

So i get an error: Types of actual and formal var parameters must be identical.

the method you used (AddPicture) can include the size of the image, Left, Top, Width and Height)

So try something like this:


If you want first to send the cursor to the end of the document (before inserting the images), try the next procedure:

procedure EndCursor;
//send cursor to the end of the active document
   Unidad : OleVariant;
   Extended : OleVariant;
  Unidad := wdStory;
  Extended := Unassigned;

Best regards
Manuel Lopez (lopem)

Author Comment

ID: 7154688

how can i know the page Width  ?

thank u

Expert Comment

ID: 7154721

Its not the page width, is the image width. You can load the picture you want to insert to a delphi image component (jpg and bmp unless you have a custom component to load tif images) and check the top, left, height and width of the image. Having this, you can stretch the image just changing the proper values.

best regards,
manuel Lopez (lopem)
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 7154742

yes , but suppose i wish to streach the image to the page width , and i dont know the page width in advance , how can i do that ?

thank u

Accepted Solution

lopem earned 200 total points
ID: 7154959

I found this (from VB for Word97 Help file):


Shapes object: Creates a picture from an existing file. Returns the Shape object that represents the new picture.
InlineShapes object: Creates a picture from an existing file. Returns the InlineShape object that represents the new picture.

Syntax 1

expression.AddPicture(FileName, LinkToFile, SaveWithDocument, Left, Top, Width, Height, Anchor)

Syntax 2

expression.AddPicture(FileName, LinkToFile, SaveWithDocument, Range)

expression   Syntax 1: Required. An expression that returns a Shapes object.

Syntax 2: Required. An expression that returns an InlineShapes object.

FileName   Required String. The file from which the object is to be created. If this argument is omitted, the current folder is used.

LinkToFile   Optional Variant. True to link the picture to the file from which it was created. False to make the picture an independent copy of the file. The default value is False.

SaveWithDocument   Optional Variant. True to save the linked picture with the document. The default value is False.

Left, Top   Optional Variant. The position (in points) of the upper-left corner of the new picture relative to the anchor.

Width, Height   Optional Variant. The width and height of the picture, in points.

Anchor   Optional Variant. The range to which the picture is bound. If Anchor is specified, the anchor is positioned at the beginning of the first paragraph in the anchoring range. If this argument is omitted, however, the anchor is placed automatically and the picture is positioned relative to the top and left edges of the page.

Range   Optional Variant. The range where the picture will be placed in the text. The picture replaces the range, if the range isn't collapsed. If this argument is omitted, the picture is placed automatically.


I also found some way to change the width and height of an active document. I havent tried yet, but I guess you can figure out how it could work (also from the help file):


This example sets the default custom envelope width and height and adds an envelope to the active document.

addr = "Tim O' Brien " & vbCr & "123 Skye St." & vbCr & "Bellevue, WA  98004"
ret = "Dave Edson" & vbCr & "123 West Main" & vbCr & "Seattle, WA  98004"
With ActiveDocument.Envelope
    .DefaultWidth = InchesToPoints(9)
    .DefaultHeight = InchesToPoints(3.85)
End With
ActiveDocument.Envelope.Insert Address:=addr, ReturnAddress:=ret


Other idea is to find out what is the relation between an image loaded to a document and the size of the active document in inches and pixels, so you can have a pretty good idea of what is the maximum size for the picture you want to add.

best regards
Manuel Lopez (Lopem)

Author Comment

ID: 7154997

yes , but suppose i wish to streach the image to the page width , and i dont know the page width in advance , how can i do that ?

thank u

Expert Comment

ID: 7155020
Hi Asi,

I dont know. Sorry. I dont have the last Word reference. Probably there is a way but I dont know how to do that.

best regards,
Manuel Lopez (lopem)

Expert Comment

ID: 9343065
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 
Post your closing recommendations!  No comment means you don't care.

Expert Comment

by:Lukasz Lach
ID: 9460888
No comment has been added lately (18 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 lopem http:#7154721

Please leave any comments here within 7 days.

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


EE Cleanup Volunteer

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
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

650 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