Solved

Word Document methods

Posted on 2002-07-14
9
690 Views
Last Modified: 2010-04-04
hello,

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
  try
    WordApp := GetActiveOleObject('Word.Application');
  except on exception do
      WordApp := CreateOleObject('Word.Application');
  end;
  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
etc...
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
Asi
0
Comment
Question by:asi
9 Comments
 
LVL 3

Expert Comment

by:lopem
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:

  MsWord.ActiveDocument.Shapes.AddPicture('d:angela.jpg',False,True,0,0,100,100,Selection.Range);

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
var
   Unidad : OleVariant;
   Extended : OleVariant;
begin
  Unidad := wdStory;
  Extended := Unassigned;
  Form1.MSWord.Selection.EndKey(Unidad,Extended);
end;

Best regards
Manuel Lopez (lopem)
0
 

Author Comment

by:asi
ID: 7154688


how can i know the page Width  ?

thank u
Asi
0
 
LVL 3

Expert Comment

by:lopem
ID: 7154721
Asi,

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)
0
 

Author Comment

by:asi
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
Asi
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Accepted Solution

by:
lopem earned 50 total points
ID: 7154959
Asi,

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)
0
 

Author Comment

by:asi
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
Asi
0
 
LVL 3

Expert Comment

by:lopem
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)
0
 

Expert Comment

by:CleanupPing
ID: 9343065
asi:
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: 9460888
asi,
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 ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

864 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now