Link to home
Start Free TrialLog in
Avatar of hertzgordman
hertzgordmanFlag for Canada

asked on

Is there a way to calculate length of string in non-proportional font?

I am looking for way to concatenate three strings in a way that an "X" will line up in column-like fashion.

The strings will look something like this:

Product ABC           X     X
Product BDC           X     -
Product CRT           -      X

The data gets merged in a Word document, where it formatted in an Arial (non-proportional font).

While it is easy to get the data to line up with proportional fonts, when it gets formatted in a font like area it end up looking like this:

Product ABC                      X     X
Product BDC            X     -
Product CRT                         -      X

I could deal with this, if I could only determine the width of the string (as Windows sees it) for the first string (the Product string).

I know there is  TextWidth function, but I think that is only for reports.
 

SOLUTION
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hertzgordman

ASKER

Thanks for the comment.

So I would set up a table with each letter, and associated with the letter a correction factor?

I guess that would take a little more work than I was hoping for!!!

Isn't there a function out there somewhere????

Avatar of HobsonT
HobsonT

Is there any reason why you could not create three fields, Text, X1, X2. In your Word document setup the merge with these three fields, use either a table or tabs to put the merge fields in the correct place?

This approcah would overcome this problem as well as the possible problem of someone changing the font in your word document.
That would certainly work in most cases.

With this merge document, I have 120 "elements" that need to be described with three characteristics.

That means I would be need 360 merge fields, which exceeds the Access limit of 255 fields.

That is why I need to concatenate the three fields together to make  a string.
Well, you could do the work by some routine.  It doesn't have to be done manually.  I may be able to give you part of what I have.

May I ask what you are trying to accomplish?

Mike
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That sounds like a good work-around.

I have another requirement that I create a Word Merge document that included many records.

With this type of VBA approach I trust I will be able to constuct an output merge document from many records?
What do you mean with many records?

Be sure, when you create your document and fill it with data, your Word-Application is hidden .Visible = False. Because, if not, there's a lot of work updating your screen ... If it's hidden it will work a lot faster ...

I use the above technique always if I have an unknown number of records that must be 'pasted' on one page, or in one table (so Mail Merge will be difficult) and it always just worked fine ...

If you have a letter, and you want to Mail Merge all the address in the header, I prefer to use the real Mail Merge approach.

Regards!
What I many by "many records" is that in Word I want to merge more than one record from the database, so that in the end I will end up with one Word document which may contain twenty or so pages, one page being for one record.

In other words, I need to do a "merge to new document".

To accomplish this with VBA, I would need to create a new Word doc, update the bookmarked fields, and then "add" this new document to final target document.

I would then (I guess) repeat this for each record in my database.  So if I had twenty records, my final document would have twenty pages, one for each record.

So the question is, how involved is it, if at all, to create a new Word Document, update it from VBA, and then append it to the end of anothe Word Document?

Because we can't use the real MailMerge (because of too many fields, and because the lay-out is a mess) we indeed must do it we jumping to all the BookMarks in the document.

If you want to create one document for several records, I think the solution you gave, is the right one.

- Open/Create your destination Word Document
- Open your (template) document with the BookMarks
- Jump to all the bookmarks and put the data
- Append this document to your Destination Word Document.
- Close your template document (don't save it) and re-open it ...
- ...

I think for 20 or 30 records, it just works fine. If you want to process 100 or more records, you could create a BATCH program that does the job for you. So, you don't have to wait until it's ready ...

Regards!
Thanks for this approach.

My instincts tell me this is the best solution.  Going to check it out and see if it works for me.

Thanks to all for the valuable info.

What I finally did was a little in between.

I went with a conventional merge but combined the "X" data from two fields into one field where I was able to manage all the permutations and combinations of characters to make things line up (still it was not easy).

I put the description info in another merge field.

Still want to try out the bookmark approach when I have more time - it sounds like the "real" way to do it.