How do I use VBA in Word 2000 or XP to calculate height & length of text strings...

T

The Goulds

Hi All!

How do I use VBA in Word 2000 or XP to calculate height & length of text
strings (based on font type/size) so I can dynamically size per-page output
from a database?

Thanks!

MG
 
D

Doug Robbins - Word MVP

Hi MG,

Not really sure what you mean by "dynamically size per-page output from a
database", but see what you can do with Selection.Information

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
M

Michael Gould

Thanks, Doug.

I am creating a label maker program for archiving insect specimens. Each
sample has a variable number of lines per label based on collection details.

What I had in mind to do was to calculate the max height per table row as I
lay it out, then cumulatively add it up and subtract that from the printable
height of the page. This way, I'd hope to fill the page by adding rows to
fit, rather than use a fixed number of rows and risk wasting paper - some of
my users would rather avoid that.

I will look at Selection.Information and see if that helps.

Thanks again!

MG
 
T

The Goulds

Tried it - Selection.information did not have a parameter suitable to the
task. When I try to get the height property of either the row or the cells,
I just get a string of nines (equivalent to wdUndefined?) - since I do not
define the row heights upon creation. This is what has kept me from
progressing as I would like. I cannot define heights based on character
counts unless I use a fixed-width font (which I don't want to use in any
case).

Thanks! MG
 
K

Klaus Linke

Hi Michael,

I'm not sure what formatting/spacing you want to change on the fly to
"dynamically size per-page output" in your labels.

Those "labels" have a fixed size and layout?
You might vertically center the text in each label to make it look good
independent of the amount of rows on it.

The built-in wizard for labels ("Tools > Letters and mailings > Envelopes
and labels") or the corresponding VBA functions could help you (if you don't
already use them).

Maybe you could run a macro after you filled the labels, and "copy fit" if
the text doesn't fit on the label (by changing to a "narrow" font, or a
smaller font size...).
http://www.mvps.org/word/FAQs/Formatting/FitCopy.htm has some tips on copy
fitting.
But probably, it makes more sense to limit the amount of text in your
records to some maximum, and choose the label layout so it fits in any case.

Greetings,
Klaus
 
T

The Goulds

selection.information(wdVerticalPositionRelativeToPage) does in fact give me
what I need - sorry, Doug, you were right on!

Thanks!

MG
 
K

Kemosabe

On Wed, 5 Nov 2003 11:03:10 -0800, "Michael Gould"

Create a hidden label with AutoSize set to true. Assign it the
appropriate font, of course. Set its text to the string you want and
then read the height and width values of the label control.
 

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