PDA

View Full Version : Align contents of textbox



vsyam
07-02-2007, 07:37 AM
Hi,

Any idea how to vertically align the contents of a textbox?

My textbox contains plain text, fields, shapes. I can get the height of the shapes and possibly the text using font size. But i cant get the height of the inscribed rectange of a field.

If anybody can please help me with finding the height of a field, that would be okay too.

Thank you for your help in advance.:help

lucas
07-02-2007, 08:19 AM
My textbox contains plain text, fields, shapes.
I'm confused by this....could you post your workbook?
click on post reply at the bottom left of the last post and then scroll down and look for manage attachments.

vsyam
07-02-2007, 10:29 AM
Hi,

workbook? I m using MS Word..

vsyam
07-02-2007, 10:36 AM
Sorry for the confusion. I am maintaining a program in vb6 that exports its content into a doc format. The program inserts a lot of textboxes with some text content, fields, shapes.. sometimes individually and sometimes a combination of these. But the content isnt properly aligned in the boxes. I got a change request to center align the content of these boxes.

Hope I am clear.

lucas
07-02-2007, 12:30 PM
Don't post your document/workbook because I still don't understand...sorry. There are several types of textboxes that you could be talking about so I am still as confused as you obviously are. I would not want something to look at so I could see what the problem might be.

vsyam
07-02-2007, 03:05 PM
well.. the textbox i am talking about is the one that you get from "Insert > TextBox" from Word's menu. I am using on Word 2000 on my system.

You can put a textbox, add a little text, then a field and put an image all in a single box. You should be able to write a macro that can place the contents of the box vertically centre aligned to the box, irrespective of the size of the box (apparently the box would be bigger than its contents).

Please tell me what else I can do to make it more clear.

lucas
07-02-2007, 05:44 PM
I'm sorry I don't know how to do that manually....

vsyam
07-02-2007, 07:12 PM
I guess I thoroughly confused you.
Otherwise, how would a guru like you not understand what the problem is about. Sorry for the miscommunication. I wish somebody can help me out.

lucas
07-02-2007, 08:38 PM
Sorry for the miscommunication
Me too actually....honestly I don't know much about word at all as you noticed when I asked you to post a workbook but I would help if I could.

I'm just saying that I don't know how you can center, etc. vertically by formatting the textbox manually let alone with code. I may be wrong and someone will come along and let us know but I'm doubtful...sorry.

fumei
07-03-2007, 01:54 AM
I don't like your tone.

I guess I thoroughly confused you.
Otherwise, how would a guru like you not understand what the problem is about.
Steve is a knowledgeable member of this forum. His request for more information was entirely valid. His request for a possible example document posted here so we can look at it, is also very valid.

If you can not bother doing that...why bother even asking for any assistance.

Steve is not a full blown Word power guy...but I sure as heck would not want to argue with him on Excel.

Look, I am not trying to be rude...but YOU don't understand it either.

You make a textbox with Insert > Textbox. (BTW: I will clearly state my bias here. I hate those things and consider them Microsoft's hand holding of people with poor design and graphic skills).

The point...let me be really simple here....of those darn Insert > Textboxes are Shapes. Not InlineShapes (which CAN be center-aligned). Any object within them, are also Shapes.

Shapes by definition are free of margin restraints. You can move them around...yes?

You can even take one of those Shapes in your textbox and......move it right out of the textbox. So, what pray tell, would center-aligned MEAN? If it is not even within the boundaries of the textbox? Hmmmm?

The answer to your question is no. Those objcts are Shapes. They are free floating graphic objects. Heck you can move one outside of the margins of the document itself. So what would center-aligned mean then?????

You can of course make them centered. But not aligned. Move each of the elements to the center....done.

COULD it be done programatically? Technically speaking....yes. It is possible to get the size values of the Shapes, and mathematically determine what would be "center".

HOWEVER, even if you did, if someone came along and changed the size of the holding textbox...those objects would not, repeat NOT, move and stay centered.

They would stay in the same location until you moved them. That is because...again...they are Shapes, and by definition are free floating and not restricted by margins.

"Centered" means half way between X and Y.

Free floating Shapes ignore X and Y. They are free to be placed where ever you want. That is, in fact, the point.
You should be able to write a macro that can place the contents of the box vertically centre aligned to the box,Except....you can't. If you could it would no longer have the properties desired in the first place...being able to move them around.

I hate those textboxes. As stated, it IS possible to get current object location/size values for these. And then, mathematically figure out a centering, and then programtatically set them.

However, it is a major, major major pain in the butt. It would be far, far easier to simply move the objects to the location and alignment you want manually.

Accessing and altering Shapes is probably the most arcane aspect of the Word object model, and definitiely not for the faint of heart.

Just to give you an idea.

Make a clean document.

Use Insert > Textbox.

In the "text" box - inside the Textbox - type something, anything.

Now insert a picture (anything).

Let's repeat what you did.

1. Insert > Textbox
2. typed text into the smaller box
3. insert > picture

To be clear - the box (control) with the text, AND the image are "IN" the Textbox created by Insert > Textbox.

Run this code:Sub TT()
Dim j As Long
j = ActiveDocument.Shapes.Count

Dim var
Debug.Print j
For var = 1 To ActiveDocument.Shapes.Count
Debug.Print var & " " & ActiveDocument.Shapes(var).Name
Next
End Sub

Result?

1 - the Shape count
1 Canvas 3 - the Shape count, space, Shape Name.

So far, so good...although look at the Name!!!

Now. Drag the box with the text so it is just a wee bit outside the Textbox. Drag the image so it is a wee bit outside the Textbox.

Run the code.

Result?

3 - the Shape count
1 Canvas 3 (var, the first shape) - the Canvas
2 Text Box 4 (var, the second Shape) - the "text"
3 Picture 5 (var, the third Shape) - the image


Starting to see this?

OK. Now select the Textbox itself. Press Delete.

BECAUSE the control with the textbox is now "outside" the Textbox, and the image control is "outside" the Textbox, you can delete the Textbox...and they are still there!!! You can still move them around as independent Shapes.

Run the code.

Result?

2 - the Shape count
1 Text Box 4
2 Picture 5

Ready for MORE weirdness????

Just to repeat where we are. There was a Textbox with a text control and image control inside it. This is considered ONE Shape.

You moved the text control and image control so part of them are outside the Textbox. These are now considered independent Shapes, and the Count = 3.

Note also the bizarre naming. Canvas 3 (even though it is the first thing done). Textbox 4 (even though it is a text control INSIDE of a Textbox. Picture 5.

Next, we deleted the textbox itself. The Shape Count = 2, as the other (now independent) Shapes are valid.

So, OK, now, move to the end of the document - remember these actions are the ONLY thing happening.

Use Insert > Textbox.

Run the code.

Result?

3 - the Shape Count
1 Canvas 7 - the new Textbox
2 Text Box 4
3 Picture 5

So even though it is only the second textbox Inserted, its Name is Canvas 7.

Put text into the "textbox" inside it. Remember, it is still inside, so it is NOT an independent Shape.

Running the code does not of course show it. But...move IT slightly outside of the second Tdxtbox - which is sort of the first as the first one is deleted....

Run the code.

Result?

4 - the Shape Count
1 Canvas 7
2 Text Box 4
3 Picture 5
4 Text Box 8

Are you getting the picture here? Notice the second Textbox (Insert > Textbox) - now the ONLY Textbox has moved UP in the index. It is Shapes(1)...even though in the document it is the THIRD Shape, and the FOURTH Insert.

More? Move the image that was in the first (now non-existent) Textbox, INTO the second (now ONLY) Textbox.

It now becomes NOT a Shape - it is part of the Shape, an element.

Bottom line? The indexing and naming is so SO WEIRD, working with code on these is an experience of hair-pulling madness.

If you insist, you need to use:ActiveDocument.Shapes(1).OLEFormat.Object to access the properties of theShape.

NOTE: while IntelliSense will show:

OLEFormat as a property of Shapes(index),

AND .Object will show in IntelliSense as a Property of Shapes(index) - as in:

Shapes(index).Object

.....ALL properties and values (size etc.) do NOT show in IntelliSense. You have to use the Object Explorer to find out what the Object properties are.

Good luck. Enter at your own risk.

fumei
07-03-2007, 02:03 AM
Actually, the REAL bottom line is this.

Word is a word processor. It is NOT a graphics application, NOR a layout application.

You seriously want to do this...use a proper tool. Quark works well.

I hate those textboxes.

lucas
07-03-2007, 06:47 AM
Hi Gerry,
Thanks for the support. It still amazes me that folks think that sarcastic remarks will make people more willing to help them. Especially when you consider that they came here for help with a problem. Sadly they are mostly US members...reflects badly on my home country.

Another one that causes me ire is the one described by unmarkedhelicopter(username) as feature creep. Where they give you just enough info to get them started and then want to change the whole layout or keep adding to it without trying to accomlish any of it on their own.