• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 689
  • Last Modified:

VBA code for creating new text style

I would like to have code for creating a new text style call "Bold" and having the same properties as the text style "Standard" but having bold instead of regular.

Saqib Husain, Syed
Saqib Husain, Syed
1 Solution
Tommy KinardCommented:
This will creat a new text style with all of the same attributes as the text style Standard. Then I change the bold to true and the name to BOLD. Ths issue I have is as long as I use the text style without bringing up the dialog box it works fine. If you open the dialog box it doesn't seem to pick up the bold. If this is unacceptable i may try to use lisp to do the dirty part.


Sub MakeBold()
    Dim NewStl As AcadTextStyle, Asd As AcadTextStyle
    Dim typeFace As String
    Dim Bold As Boolean
    Dim Italic As Boolean
    Dim charSet As Long
    Dim PitchandFamily As Long
    Const TMPF_TRUETYPE = &H4
    For Each Asd In ThisDrawing.TextStyles
        If Asd.Name = "Standard" Then
            Asd.GetFont typeFace, Bold, Italic, charSet, PitchandFamily
        End If
    Set NewStl = ThisDrawing.TextStyles.Add("BOLD")
    If Not Bold Then Bold = True
    NewStl.SetFont typeFace, Bold, Italic, charSet, TMPF_TRUETYPE
    ThisDrawing.ActiveTextStyle = NewStl
End Sub

Open in new window


Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now