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

x
?
Solved

Word Document methods

Posted on 2002-07-14
9
Medium Priority
?
720 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
[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
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
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

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
 
LVL 3

Accepted Solution

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

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