简体   繁体   中英

Excel VBA - append formatted text to cell

I need to add a "padding-bottom" to a cell in VBA.

A way to get what I need might be to append to a cell a char with smaller font size (let's say a small dot) in a new line.

How can I achieve this in VBA?

The following will insert "my text" into range A1, you can adapt it as you need.

It works as follows:

  1. Get the current number of characters in Range A1 (lOldTextLen)
  2. Insert two line breaks and "my text" into Range A1
  3. Update the characters in Range A1 to font size 8, starting from the end of the previous text (using lOldTextLen)

     Dim sText As String Dim lOldTextLen As Long sText = "my text" lOldTextLen = Len(Range("a1")) Range("a1").Value = Range("a1").Value & vbNewLine & vbNewLine & sText Range("a1").Characters(lOldTextLen + 1).Font.Size = 8 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM