PDA

View Full Version : Excel to Word help



doubtfire
08-21-2012, 06:02 PM
I have transferred from Excel tabular data to Word successfully, the only thing left is the underlining.
eg if the amount is 0 then it only highlights one character in this case.
How can I underline the whole table fields the whole length even there is only 1 or 2 characters filled in this field?
Any suggestion.
Thanks.:help

fumei
08-21-2012, 08:52 PM
I am having a hard time understanding what you are asking. Whole table fields? What fields? What do you mean by "whole length"?

Can you post an example?

Frosty
08-22-2012, 06:39 AM
I think you might want to look at borders (cell vs paragraph) when within a table cell

doubtfire
08-22-2012, 07:02 AM
First of all, thanks for the response to all.
I have the followings from Excel

Col1 Col2
Cust01 9,999
Cust02 0

after transfer to Word (tabular format)
the Col2 of Cust01 is underline based on 5 characters.
the Col2 of Cust02 is underline based on 1 character.

My expectation is the underlining is based on the length of column Col2, no matter is single/double underline.

Hopefully I am clear.
Thank you.:help

Frosty
08-22-2012, 07:38 AM
Well, you have to decide on the format you want, and then we can potentially help with coding (if necessary).

Do you want paragraph borders? Do you want underlining using some tabs/tab stops? Do you want to use borders and blank columns? The first two can be style formats too, so it may be a matter of setting some styles up properly.

You're trying to translate something (number formatting) which doesn't have a direct correlation in Word formatting. So you should make the first decision based on your available options, then you can get some help from there

doubtfire
08-22-2012, 07:48 AM
Frosty,

Thank you again.
You're right I'm using cells unit of Word table like this for underline formatting
oTable.Rows(VarRow).Cells(VarCol).Range.Underline = wdUnderlineSingle
oTable.Rows(VarRow).Cells(VarCol).Range.Underline = wdUnderlinedouble

Let me know what suggestions close to this otherwise I have to re-code everything based cell/table/paragraph.

Not too much knowing about Word object.

Thank you.: pray2:

Frosty
08-22-2012, 07:56 AM
Forget programming for a second... I can't give you the programming if I don't know what you want the formatting to look like.

You're not using the cells object, you're using the Range object... which means you are formatting individual characters underlined (which is why 0 is a single digit width of underlining).

But if you want the whole cell underlined... that's one thing.
If you want the width of the cell minus a little underlined, that's something else.

You have to provide a sample of what you want, otherwise I'm just guessing.

doubtfire
08-22-2012, 08:00 AM
Frosty,

I want to underline the whole cell length no matter how long the content is.
Please throw some simple code.
Thanks.:banghead:

Frosty
08-22-2012, 08:08 AM
Can you please look up borders through the native interface, and explore applying borders to both the cell and the paragraph, and then see which you like?

From there, you could try recording a macro to do one of those two formats.

This is the way to learn.

macropod
08-22-2012, 08:16 AM
Try something based on:
With oTable.Cell(VarRow, VarCol).Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
End With

doubtfire
08-22-2012, 08:29 AM
Thanks.

Frosty
08-22-2012, 09:11 AM
That's another way to learn. But you miss out on learning about your options, and instead have either a) had someone else make a formatting decision for you (I would have chosen paragraph borders instead if cell borders, but both can be right) or b) come back an have more posts saying "that's not quite right, because I need some space between my columns" (or some other further formatting adjustment).

It is my belief that you should, where possible, use programming to speed up doing things you know how to do... Not use it to cover up lack of knowledge about your options on what you can do.

doubtfire
08-22-2012, 09:20 AM
Frosty,

I agree with you.
BTW I have added an Excel column in between to prevent multi-columns
sticking together not to confuse users.
Thanks and I'm open to any advice and suggestions.
Any advice, suggestions and/or ideas from any levels of contributors are welcome. They are all precious to make ideas to my project although I might adopt the whole or partially only.
Salute! :beerchug:

Frosty
08-22-2012, 09:28 AM
You remove the need for blank/empty columns if you utilize paragraph borders rather than cell borders.

Cell borders border the cell. Paragraphs borders are defined by the left/right indent of the paragraph (each cell contains at least one paragraph).

By default, paragraph borders applied to multiple paragraphs only show up on the last paragraph with such formatting applied.

In most cases, I think this is a better formatting choice for a table which has total columns, total rows, etc. Having blank columns and rows for the purposes of formatting can cause problems (the least of which that you end up tabbing into "meaningless" cells when navigating such a table with the keyboard).

You might want to look at the alternative to Paul's code applying to the cell, and instead apply to the paragraph format of every paragraph in the cell:

With oTable.Cell(VarRow, VarCol).Range.ParagraphFormat.Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
End With

But what you should really do is explore all of the various options you have in terms of table formatting. Depending on the version of word you are using, there are some really slick table formats pre-built for you. That exploration may cause you to have some new ideas about formatting.

And, of course, you can define styles in the document which contain chunks of formatting (even the paragraph borders), and then simply make sure that style exists in the document, and apply it to the various cells. Not to open an entire styles discussion on what is a simple request-- but there is a lot of understanding that can come from this simple question.

doubtfire
08-22-2012, 09:33 AM
Frosty,

Those advice or suggestions cost more than a beer.
Salute .... and more beer to come ....

:beerchug::beerchug::beerchug::beerchug::beerchug::beerchug:
........... when you get a chance and have more ideas ......

.....do not hesitate to throw more lines .............

macropod
08-22-2012, 09:39 AM
Another way, with the original approach, is have the paragraph left aligned with a right or decimal tab at the required position, then to precede whatever's input with a tab character and underline the lot. This means all cells can have the same amount of underlining without applying a full-width border.

doubtfire
08-22-2012, 09:46 AM
Thanks.

... just a Canadian beer :beerchug: