Partially Bold WordDoc table cell RRS feed

  • Question

  • Within Excel VBA, I have created a string of which I wish to Bold say the first 10 characters only. I place the text in the cell and then the following line I attempt to bold a substring of it.

    This is what I have and below is the error I encounter when code is ran.

        With WordDoc.tables(8)
                         .Rows.Add (.Rows(.Rows.Count))
                        .Cell(.Rows.Count - 1, 1).Range.Text = "Argentina - Regulatory Agency - Notes Notes"
                        .Cell(.Rows.Count - 1, 1).Range.Characters(1, 9).Font.Bold = True  (this errors out)

    I have tried various flavors of the .characters including




    .cell(rows.count-1,1).range.characters(etc).font.fontstyle = "Bold"

    all produce various errors

    "invalid number of parameters"

    "object does not exist within collection"

    I simply want to bold a portion of text in the cell of a worddoc table generated in Excel.

    thanks for reviewing.

    Wednesday, March 11, 2015 10:26 PM

All replies

  • Characters(start, length) is Excel VBA, not Word VBA.

    You should be able to do something like this:

        Dim rng As Word.Range
        With WordDoc.Tables(8)
            .Rows.Add .Rows(.Rows.Count)
            Set rng = .Cell(.Rows.Count - 1, 1).Range
            rng.Text = "Argentina - Regulatory Agency - Notes Notes"
            WordDoc.Range(rng.Start, rng.Start + 9).Font.Bold = True
        End With

    If you're using late binding (i.e. you haven't set a reference to the Microsoft Word n.0 Object Library), declare rng as Object instead of as Word.Range.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, March 14, 2015 11:58 AM