Inserting pictures and formatting them in a word document

B

b

Hello,

I need to write a program (VB6/C#) that automates Word (97) and does
the following:
- takes a bunch of image files (jpg)
- inserts them into a new document
- resizes them and makes sure there are 2 on each page (each one is
15x10cm)

I managed to insert the pictures and resize them, but i'm having
trouble with setting their position so that there will be two on each
page. I tried inline shapes and it basically works, but I need spacing
between the images which I try to handle with TypeParagraph but it
doesn't seem to help much.

Please help me solve this problem.

Thanks,
S. Neumann
 
D

Doug Robbins

I would set up a table with appropriately sized cells for the photos and an
empty row between the rows containing those cells to provide the spacing.


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
D

Dave Lett

Hi S. Neumann,

As an alternative to Doug's suggestion, you could change your page
orientation and insert a tab character between the two images.
Here's how I might tackle the problem:

Insert and resize ImageN
Inset tab after new ImageN
Insert and resize ImageN + 1
Insert paragraph after ImageN + 1
Repeat until all images are inserted

Select whole document and Define tabstop (so that alignment = right)
Define page setup (landscape and top/bottom margins so that it leaves space
a little larger than 15 cm, which will force subsequent paragraphs with
inline shapes to the next page)

HTH,
Dave
 
B

b

Hi Dave!

Thanks for your quick reply.

Unfortunately, both solutions aren't good for my cause because after I
create the document, the user has to edit it (add annotations to the
images, etc.). Sometimes they'll want to resize the images, etc.

Now, if I use a table, for some strange reason Word doesn't pop up the
regular context menu when you right click an image inside a table cell.

If I do it your way, I first have to rotate all the images which will
bug the user when he writes his/her annotations because the image is
rotated...

Can't I automate a simple routine that inserts an inline image, types a
couple of CrLfs, inserts another inline image to come right after those
line breaks, inserts a page break and so on?

How do I tell an inline image where to be inserted? Or maybe how do I
tell a non-inline image not to be on the first page? (or how do I
calculate its top from the first page's top margin so that every odd
image is say 1 cm from the top margin of its page and every even image
is 15 cm from the top margin of its page?)

Thank you,
S. Neumann
 
C

Chuck

Your suggested solution will work fine (adding the image, positioning it,
anchoring it, inserting page breaks every two images). You may need to fill
each page with enough paragraphs to allow users to type their comments.

You may find that inserting the images as Shapes (rather than InlineShapes)
gives you more flexibility in terms of placement, sizing, etc.

Here's a sub I use to insert an image from an image file and then
position/size the shape:

Sub AddLogo(strFileName As String, strLogoName As String, rngRange As Range,
sglHeight As Single, sglWidth As Single, sglHorizPos As Single)

Dim shpShape As Shape

Set shpShape = ActiveDocument.Shapes.AddPicture _
(FileName:=BOILERPLATE_PATH & "\" & strFileName, _
linktofile:=False, _
savewithdocument:=True, _
Anchor:=rngRange)

With shpShape
.Name = strLogoName
.LockAnchor = True
.LockAspectRatio = msoTrue
.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = _
wdRelativeVerticalPositionPage
.Height = CentimetersToPoints(sglHeight)
.Width = CentimetersToPoints(sglWidth)
.Left = CentimetersToPoints(sglHorizPos)
.Top = CentimetersToPoints(1.25)
End With

End Sub

You call the AddLogo sub from another sub and supply the parameters such as
file name, insertion point (as a range), height, width etc.

HTH
Chuck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top