Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables,microsoft.public.word.vba.beginners,microsoft.public.word.vba.general
Blackberry Blackberry is offline
external usenet poster
 
Posts: 1
Default Big ask - need help formatting data from vb to word doc

Hi All

I know this is a big ask, but I could really do with some help making the
below reliable and as fast as possible.

In essence I have a word doc consisting of 1 table, which has about 20 cols
and 6 rows.

In my VB app, I have a list of say 30 - 35 people, who have to go into
specific cells in this word doc table.

I have managed to do this by using a CASE statement to concat the names (+ a
carriage return) into an array (let's say of 20 values, ie 20 cols for 1
row) and then I squirt the content of each value in the array into the
relevant cell bookmarks in the Word doc.

I have this bit working perfectly. The problem is that these people are
flagged with certain attributes, which in turn need to be graphically
represented on the word doc either by text background colours, text
foreground colours or styles (ie bold, italic & underline).

I have all of this info available to me in an array, but my problem is that
I don't APPEAR to be able to 'tag' these styles to the people. For example
if I could use tags like I can in HTML, I could do the following in my
array:

Array(0) = "redboldFred Smith/bold/red" & vbCrLf &
"greenitalicFred Smith2/italic/green" & vbCrLf
..... etc...

Array(1) = "yellowFred Smith3/yellow" & vbCrLf &
"underlineFred Smith4/underline" & vbCrLf .... etc...

and so on...

What I'm trying to say is that the tags allow me to format each person in
the array, but I don't think Word VBA can do this - am I right?

Can you think of another way round this, bearing in mind that I don't know
how many people will be in each cell and each person can have different
attributes to the others in the same cell.

Thanks for any pointers you can give.


  #2   Report Post  
Posted to microsoft.public.word.tables,microsoft.public.word.vba.beginners,microsoft.public.word.vba.general
Shauna Kelly Shauna Kelly is offline
external usenet poster
 
Posts: 571
Default Big ask - need help formatting data from vb to word doc

Hi Blackberry

I would do this as follows:

1. Create a character style in the document for each person. For example,
for Jim it might be:

Dim oDoc As Word.Document
Dim oStyle As Word.Style

'Get a reference to your document in some appropriate way
Set oDoc = ActiveDocument

'Create a new character style
On Error Resume Next 'in case the style already exists
Set oStyle = oDoc.Styles.Add(Name:="Jim", Type:=wdStyleCharacter)
On Error GoTo 0

With oStyle.Font
'Set the attributes of the font
'See VBA help for more options
.Underline = wdUnderlineSingle
.Color = wdColorBrightGreen
.Bold = True
End With


2. Don't concatenate your data into one string for each cell. Instead, do
each name individually, something like this:

Dim oTable As Word.Table
Dim oCell As Word.Cell
Dim rng As Word.Range

Set oTable = whatever is appropriate in your circumstance

set oCell = however you identify the cell to add the text to

'Get the range of the cell
Set rng = oCell.Range

'Collapse to the end
rng.Collapse wdCollapseEnd
rng.MoveEnd wdCharacter, -1 'get back into the cell

'Add the name of a person
rng.InsertAfter " Jim"

'rng will have expanded to encompass the text so
'we can format the text
rng.Style = "Jim"



Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


"Blackberry" wrote in message
...
Hi All

I know this is a big ask, but I could really do with some help making the
below reliable and as fast as possible.

In essence I have a word doc consisting of 1 table, which has about 20
cols
and 6 rows.

In my VB app, I have a list of say 30 - 35 people, who have to go into
specific cells in this word doc table.

I have managed to do this by using a CASE statement to concat the names (+
a
carriage return) into an array (let's say of 20 values, ie 20 cols for 1
row) and then I squirt the content of each value in the array into the
relevant cell bookmarks in the Word doc.

I have this bit working perfectly. The problem is that these people are
flagged with certain attributes, which in turn need to be graphically
represented on the word doc either by text background colours, text
foreground colours or styles (ie bold, italic & underline).

I have all of this info available to me in an array, but my problem is
that
I don't APPEAR to be able to 'tag' these styles to the people. For
example
if I could use tags like I can in HTML, I could do the following in my
array:

Array(0) = "redboldFred Smith/bold/red" & vbCrLf &
"greenitalicFred Smith2/italic/green" & vbCrLf
.... etc...

Array(1) = "yellowFred Smith3/yellow" & vbCrLf &
"underlineFred Smith4/underline" & vbCrLf .... etc...

and so on...

What I'm trying to say is that the tags allow me to format each person in
the array, but I don't think Word VBA can do this - am I right?

Can you think of another way round this, bearing in mind that I don't know
how many people will be in each cell and each person can have different
attributes to the others in the same cell.

Thanks for any pointers you can give.




Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Losing formatting of data when merging with word doc! Curtis Mailmerge 1 March 16th 06 04:58 AM
formatting table data after fix to Error in Word Calculations nojar Tables 1 June 14th 05 02:35 PM
Formatting fields in Word (using Excel as Mail Merge Data) - need. John Mailmerge 1 April 12th 05 12:24 PM
Formatting a word mailmerge with Excel data source Tracey Mailmerge 2 March 15th 05 02:07 PM
How do I retain formatting from an Excel Data File to a Word Merg. Pookas Microsoft Word Help 5 March 14th 05 10:32 PM


All times are GMT +1. The time now is 09:29 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"