PDA

View Full Version : Solved: How to Fit A Picture Into Table?



karpatov
08-29-2007, 12:12 PM
Dear members,
I would like to ask if there is a way how to force pictures inserted into individual cells of the table to adjust their sizes to the sizes of the cells.

A more general question:
I see that in excell there is a WorkBook, WorkSheets, Columns, Rows and Cells. What is basic unit of Word document? I would like to have a macro that reads names of pictures in a folder into an array (finished) and fill them into several 3*2 tables (here I have the problem with fitting the pictures) and end up with one such a table on a page (is a page a unit like worksheet in Excell)?

Pseudocode
For i = 1 To 3
InsertPicture (ActiveDocument.Shapes.AddPicture _)
Insert TextBox in the picture top cornerleft (Set newTextbox = ActiveDocument.Shapes.AddTextbox)
Selection.InsertBreak Type:=wdPageBreak
Next

I end up with
1st page: 2 pictures (one covering the other)
2nd p. - empty
3th p. - empty
4.th p. - picuture + all 3 textboxes covering eachother

Thanks for help



Thanks for replies
karpatov

fumei
08-29-2007, 01:48 PM
Hmmmmm.

Working backwards....

No, a page is not a unit in Word. A "page" is a calculated range. Word has to repaginate to figure out what a page contains, AND that calculation is 100% dependent on the installed printer driver. A different printer driver (even one for the same printer!) and a "page" can be quite different.

The basic unit of Word? Hmmmm. A character.

The next basic unit is a paragraph. This is totally tied into the basic object in Word, which is Range.

Interestingly enough, there is no real word object in Word.

Getting your tables to be one per page is not hard. Just set the tables to have a page break before.

As for (I assume) automatically sizing the images to the cells, this depends. Generally speaking....no. Technically, can it be done? Yes, but it would take fairly serious fussing.

I take it that what you mean by this is, if you change the cell size (say by adding text in another column, same row), the image will automatically size itself.

There is no direct linkage between them - the image and the cell dimensions. You would need to get the cell dimension numbers, then make the image dimension numbers match. Taking into account any spacing within the cell.

karpatov
08-30-2007, 06:17 AM
Thanks for reply.
1.
"You would need to get the cell dimension numbers, then make the image dimension numbers match. " Is it possible to do this in VBA and Word or I will have to resize the pictures in some other program?

2.
Following question stems again from my confusion about organisation of Word document.
I would like to insert one picture from a directory per page, moreover I want to put a textbox with number into the right corner of a picture. All this I am trying to do through a For Next construction.

How to tell Word that the next picture should come to next page? Page Break doesnt seem to work in the loop properly. Moreover while pictures are inserted on different pages (OK), textboxes are not. Seems that their positions are given relative to something else than pictures. Moreover total empty pages apear.


What if I want to insert a picture + a table with description per page? here page break completly destroys everything.

Thanks for help

geekgirlau
08-30-2007, 07:05 PM
If you are attempting to create an image catalogue of sorts, I would suggest that PowerPoint would be a better tool for this. IMHO Word is not the best tool for this task.

karpatov
08-30-2007, 09:46 PM
I am supposed to write a report about drug effects with microscopy pictures.
So I need text + pages with photos. Because there are 6 pictures for every experiment (and they should come to 1 page as 2*3 set) and dosens of experiments I would like to automat the precedure.




If you are attempting to create an image catalogue of sorts, I would suggest that PowerPoint would be a better tool for this. IMHO Word is not the best tool for this task.

geekgirlau
08-30-2007, 10:26 PM
Can you post a couple of sample pages of what you are trying to achieve?

fumei
08-31-2007, 12:16 PM
Oh boy. This is not trivial.

Seems that their positions are given relative to something else than pictures.
Indeed textboxes ARE relative to something. They have an anchor.

I am confused;

1. "Because there are 6 pictures for every experiment (and they should come to 1 page as 2*3 set) "


2. "I would like to insert one picture from a directory per page"

This seems like a contradiction.

karpatov
09-03-2007, 01:46 AM
It is really contradiction, sorry for that. First I intended not to complicate the question by the fact that it should be a six-pack of pictures, but than I realised that there is Shapes.AddPicture enabling to set Top and Left and AddPicture for a Range which doesnt have these parametrs.

so I would like to have
- six pictures for a page organised 3*2 and six textboxes placed in top left corners of the pictures (works great for a single page)
- many pages organised as described above

-pictures/textbox description (path) are supplied from an array

So the solution was simple :

For i in 1 To ....

InsertPictures 2, 3, PathSubArray '(a procedure inserting 2*3 pictures from files indicated by an array using ActiveDocument.Shapes.AddPicture, sizes are given by dividing difference of margins by the 2 or 3 respectively)
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.MoveUp Unit:=wdLine, Count:=1

Next

My question still is how to do similar operation in sections:
1. create x sections by a loop (I can do that)
2. tell Shapes.AddPicture that it should start in the begining of the section (works for text where cursor is automaticly set at the right position)

Is it possible to read some tutorial about Word and VB discussing Sections, Ranges and Anchors? I am used to work in Excell and there is everything crystal clear with layout. Thanks for help

karpatov
09-03-2007, 01:57 AM
So I have pictures with texboxs on top of them - how to change the font of the text?

I am using ActiveDocument.Shapes.AddTextbox but it seems that there is no option for setting fontsize.

Tx

Set newTextbox = ActiveDocument.Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, Width:=AvlWidth / PicPerRow / 10, Height:=(AvlWidth / PicPerRow) / PicRatio / 10, Left:=(-1 + i) * AvlWidth / PicPerRow + ActiveDocument.PageSetup.LeftMargin, Top:=(-1 + j) * (AvlWidth / PicPerRow) / PicRatio + ActiveDocument.PageSetup.TopMargin)
newTextbox.TextFrame.AutoSize = True
newTextbox.TextFrame.TextRange = x

fumei
09-03-2007, 09:45 PM
Use the .Font.Name property. Set it before you insert the text.newTextbox.TextFrame.TextRange.Font.Name = "Arial"
I am trying to understand what the "x" may be.

.TextRange itself is a Range, so what is "x"???

The default property (of any Range), it is true, is text.
newTextbox.TextFrame.TextRange = "Hello World"
newTextbox.TextFrame.TextRange.Text = "Hello World"are technically equivalent, but IMO, this is not great coding. It is better to be explicit. As I think you may see my point in that I have no real idea what "x" is meaning.

I think it is a string, but generally speaking, when dealing with code, I would rather know something, than think I know. It would also make it easier to use With statements.With newTextbox.TextFrame
.AutoSize = True
With TextRange
.Font.Name = "Arial"
.Font.Size = 16
.Text = x
End With
End With...or whatever.

karpatov
09-04-2007, 05:44 AM
I would like to thank you for the advices I was given. Is it me who is supposed to flag the thread as solved (how should I do that) or is it administrator?

:-) still I would like to know whether:
Is it possible to read some tutorial about Word and VB discussing Sections, Ranges and Anchors? I am used to work in Excell and there is everything crystal clear with layout. Thanks for :-)

fumei
09-04-2007, 11:16 AM
I do not know of a specifc tutorial on Sections, Ranges and Anchors. There is some stuff around on Sections and ranges, but information on Anchors is scarce.

Take at look at the Word Object Model, that may help.

Unfortunately the object model regarding InlineShapes and Shapes is rather weird, and can cause major shaking of your head.

Yes, it is your thread. You mark it Solved.