Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Right justify numeric fields in Word with VB code

Status
Not open for further replies.

EDB2

MIS
Sep 11, 2002
36
US
I originally posted this question in the Visual Basic forum, but got no replies. I'll try again in this forum, any help would be appreciated.

I'm having a heck of a time getting my numeric fields to right justify in a simple list report. I'm generating a Word document through VB6 and using an ado recordset as my source. I decided not to use DataReports because I'm picking my (Oracle) database at run time and everything I've found for DataReports requires that I specify the database at design time.

I first tried using .SELECTION.TYPETEXT to create the detail lines of the report but the numeric fields were straggling all over the place. I was Formating the fields as "##,##0.0" but it was collapsing the number to the left and I couldn't come up with a way to right align them.

I decided to go to a table instead (which I prefer as it solves my word wrap problem in description fields), but the numeric fields are still left justifying instead of right justifying inside the cell and I can't find any alignment property that seems to work with .CELL. I tried playing around with .LEFTPADDING, trying to subtract the length of the data from the width of the cell to see how much padding I needed, but I can't figure out how to translate the length of the field to points - I tried PicaToPoints as that seemed the closest option but it didn't work. I'm still using FORMAT and the numeric data is still collapsing to the left when there are no digits, the place holders don't seem to be working at all.

 
Hi EDB2,

Alignment is a Paragraph Format.

If your selection is somewhere in the paragraph you want right justified, you can use ..

Code:
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight

If not you'll have to refer to it some other way like ..

Code:
ActiveDocument.Paragraphs(1).Alignment = wdAlignParagraphRight

In a table cell you need to do something like ..

Code:
.Cell(1, 1).Range.ParagraphFormat.Alignment = wdAlignParagraphRight

I'm no expert in this but that should be enough to get you going in the right direction.

Enjoy,
Tony
 
That's exactly what I needed Tony, thank you! It never occurred to me to look at paragraph formatting for the contents of a cell - this language sure is a wild and bumpy ride.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top