Results 1 to 3 of 3

Thread: VBA changed font size in word table

  1. #1

    VBA changed font size in word table


    my code copies some excel data into a word dokument with a table with 4 cloumns and 9 rows. It is important, that the cell size is not changed, but all the input data is in the cell. My solution is, that i check the lenght of the input-data and then reduce the font size in the word table cell only. This is the code for this:

    If Len(wbsource.Sheets(1).Cells(j, 3)) < breitSize1 Then
        appWord.ActiveDocument.Tables(1).Cell(2, 1).Range.Font.Size = breitFont1
        appWord.ActiveDocument.Bookmarks("C1").Range.Text = wbsource.Sheets("Sheet1").Cells(j, 3)
    My problem is, it changes the font size of the whole column. Has anybody an idea, why this can happen. I tried this before with another word dokument and it worked, but the actual word dokument is made by somebody else.

    Thanks in advance!

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Jul 2008
    The code you posted applies breitFont1 to only one cell, not to a whole column, and inserts only a single Excel cell at a 'C1' bookmark in the document - without applying any formatting.
    Paul Edstein
    [MS MVP - Word]

  3. #3
    It looks as though this code is run from Excel and it is not know what the various variables and bookmark refer to.
    In order to format only the range in the cell, using Word vba from Excel you need something like

    Dim oCell As Object
        Set oCell = appWord.ActiveDocument.Tables(1).Cell(2, 1).Range
        With oCell
            .End = .End - 1    'remove the cell end character from the range
            .Text = "This is the content of the range"
            .Font.Size = 8    'the font size of the range
        End With
    Graham Mayor - MS MVP (Word)
    Visit my web site for more programming tips and ready made processes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts