Solved

Word Document methods

Posted on 2002-07-14
9
689 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

12 Experts available now in Live!

Get 1:1 Help Now