Paragraph formating with word table

DevAccess

Registered User.
Local time
Today, 10:01
Joined
Jun 27, 2016
Messages
321
Hello

I would like to have Paragraph(s) in the word table cell formatted as below:

In table I would have below text

Experience : --> this has to be bold

1> Experience comprises of company name, position hold, start and end date --> one string which would cover this -->this should be bold, the data comes from database query.

2 >Experience in detail --> from query memo field. --> this should be non bold format.


THe above point 1 and 2 could repeat based on recordset result found given criteria.

and this is within table cell for example cell (8,1).

Can anyone help me on this how to achive using this ??

Below is the code i tried but it does the require things but after operation it makes all the cell text to BOLD which I dont want...
Code:
  With ActiveDocument.Tables(1).Cell(7, 1).Range
        .Font.Name = "Calibri (Body)"
        .Font.Size = 12
        .Font.Bold = True
       ' .Font.Underline = True
       
        .Text = "Experience" & vbCrLf & vbCrLf
    End With

   
   Dim composite As String
            If rsGetExp.RecordCount <> 0 Then
            While Not rsGetExp.EOF
           
            composite = rsGetExp.Fields("Company Name").Value & ", " & rsGetExp.Fields("Position Held").Value & ", " & rsGetExp.Fields("Start Date").Value & " to " & rsGetExp.Fields("End Date").Value & vbCrLf
                               'Select the whole cell
                  ActiveDocument.Tables(1).Cell(7, 1).Select
                  'Move to the right
                  Selection.Collapse Direction:=wdCollapseEnd
                  'Move back to the left
                  Selection.MoveLeft wdCharacter, 1
                  'Add the text (using the myText1 format)
                    Selection.Range.Text = composite
                  'Select the on word the right (myText2)
                  Selection.MoveRight Unit:=wdCharacter, Count:=Len(rsGetExp.Fields("Company Name").Value & ", " & rsGetExp.Fields("Position Held").Value & ", " & rsGetExp.Fields("Start Date").Value & " to " & rsGetExp.Fields("End Date").Value), Extend:=wdMove
                'Format myText2
                  Selection.Range.Font.Underline = False
                  Selection.Range.Font.Bold = True
                  Selection.Range.Font.Size = 12
 '   Selection.Collapse Direction:=wdCollapseEnd
                If rsGetExp.Fields("Experience in detail").Value <> "" Then
                         ActiveDocument.Tables(1).Cell(7, 1).Select
                         Selection.Collapse Direction:=wdCollapseEnd
                        ' Move back to the left
                         Selection.MoveLeft wdCharacter, 1
                         'Add the text (using the myText1 format) &
                         Selection.Range.Text = rsGetExp.Fields("Experience in detail").Value & vbCrLf & vbCrLf
                          Selection.MoveDown Unit:=wdParagraph, Count:=Trim(Len(rsGetExp.Fields("Experience in detail").Value)), Extend:=wdExtend
                         Selection.Range.Font.Underline = False
                         Selection.Range.Font.Bold = False
                         Selection.Range.Font.Size = 12
                End If
                rsGetExp.MoveNext
            Wend


Please
 
Last edited:
This belongs in the Word forum.
Output the file to Word without the formatting. Record a Word macro while you add the formatting.
Look at the code it creates and figure out how it works.

Judging by the fact you are using lots of selects you may be doing this already.

You should really remove them. Select moves the cursor around in the document and forces a screen update which is really slow.

i.e.
Code:
ActiveDocument.Tables(1).Cell(7, 1).Select
Selection.Collapse Direction:=wdCollapseEnd

is the same as
Code:
ActiveDocument.Tables(1).Cell(7, 1).Collapse Direction:=wdCollapseEnd

but slower.
 
I do what Static suggests ie record a macro in the Word document and then paste the resulting VBA into Access, with any modification as necessary. I consider it better to have the control of the formatting in Access, not have a separate macro in a Word template.

As to why the why the whole cell text is bolded, I would make the document visible and step through your code line at a time to see where the issue is. Unfortunately, I'm not adept at checking word vba.
 

Users who are viewing this thread

Back
Top Bottom