Change Font of Word Textbox

modest

Registered User.
Local time
Yesterday, 23:01
Joined
Jan 4, 2005
Messages
1,220
Does anyone know how to change the font of a textbox? I know how to change the font of all the text, but I am unsure how to change just part of the text's font.

For instance, let's say I have code:

Code:
Public Function CreateStateSummary()
    Dim objWordApp  As Word.Application
    Dim objWord     As Word.Document
    Dim oSel        As Word.Selection
    Dim txtTitle    As Word.Shape
    
    Set objWordApp = CreateObject("Word.Application")
    Set objWord = objWordApp.Documents.Add
    Set oSel = objWord.Application.Selection
        
    objWord.Application.Visible = False
      
    Set txtTitle = objWordApp.ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 89, 69, 400, 25)
    With txtTitle
        With .TextFrame
            .TextRange.Font.Name = "Arial"
            .TextRange.Font.Bold = True
            .TextRange.Font.Size = 18
            .TextRange.Text = "TITLE Okay"
        End With
    End With

    objWord.Application.Visible = True
End Function

"TITLE Okay" is the text in the textbox.
I want to keep "TITLE" as Arial, but change "Okay" to Times New Roman

Does anyone know how to do this? I really want to keep them both in the same textbox, otherwise I would make two different textboxes as a workaround.

Thank you all,
Modest
 
I cant see how to do it with a range but by using selection you could do it like this. not the best method probably though

With .TextFrame
.TextRange.Font.Name = "Arial"
.TextRange.Font.Bold = True
.TextRange.Font.Size = 12
.TextRange.Text = "TITLE Okay"
.TextRange.Select
Selection.MoveRight Unit:=wdCharacter, Count:=10
Selection.MoveLeft Unit:=wdCharacter, Count:=4, Extend:=wdExtend
Selection.Font.Name = "Times New Roman"
Selection.Collapse
End With

HTH

Peter
 
Yes. I also submitted this post on another forum (Tek-Tips.com) to which I received a reply from Tony Jollans:
Code:
With .TextFrame
    .TextRange.Font.Name = "Arial"
    .TextRange.Font.Bold = True
    .TextRange.Font.Size = 18
    .TextRange.Text = "TITLE Okay"
    .TextRange.Words(2).Font.Name = "Times New Roman"
End With

If the text in the textbox was "Hello this is my title This is the font I want to change" and I only wanted to change the font of "This is the font I want to change" An option was to rewrite it doing the following:
Code:
With txtTitle
    With .TextFrame
        .TextRange.Font.Name = "Arial"
        .TextRange.Font.Bold = True
        .TextRange.Font.Size = 18
        .TextRange.Select
        Selection.TypeText "Hello this is my title"
        Selection.Font.Name = "Times New Roman"
        Selection.TypeText "This is the font I want to change"
    End With
End With

The link to the post is here for anyone interested:
http://www.tek-tips.com/viewthread.cfm?qid=1074452&page=1
 
Last edited:

Users who are viewing this thread

Back
Top Bottom