Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA使同一文本框中的不同单词具有不同的字体大小_Vba_Powerpoint - Fatal编程技术网

使用VBA使同一文本框中的不同单词具有不同的字体大小

使用VBA使同一文本框中的不同单词具有不同的字体大小,vba,powerpoint,Vba,Powerpoint,标题几乎说明了这一切,但为了让它更清楚一点,我想通过VBA创建一个文本框,上面写着“此文本的字体大小应为24,此文本的字体大小应为20。” 现在,我正在使用自己的函数创建文本框,如下所示。干杯,谢谢你的帮助 Sub textBox(textBoxText As String) Dim myTextBox As Shape With ActiveWindow.Selection.SlideRange Set myTextBox = .Shapes.AddTextbo

标题几乎说明了这一切,但为了让它更清楚一点,我想通过VBA创建一个文本框,上面写着“此文本的字体大小应为24,此文本的字体大小应为20。”

现在,我正在使用自己的函数创建文本框,如下所示。干杯,谢谢你的帮助

Sub textBox(textBoxText As String)
    Dim myTextBox As Shape
    With ActiveWindow.Selection.SlideRange
        Set myTextBox = .Shapes.AddTextbox _
            (Orientation:=msoTextOrientationHorizontal, Left:=153, Top:=50, _
            Width:=400, Height:=100)
        myTextBox.TextFrame.TextRange.Text = textBoxText
        myTextBox.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter
        myTextBox.TextFrame.TextRange.Font.Bold = msoTrue
        myTextBox.TextFrame.TextRange.Font.Name = "Arial (Headings)"

    End With
End Sub

不需要RichTextBox。答案在于TextBox的TextFrame中TextRange对象的属性(真是太多了!)。基本上,您可以分析/遍历此范围对象内的文本,如果您根据段落(或句子、单词、字符等)进行选择,则可以应用不同的文本效果

Sub CreateTextbox()
    Dim MyTextBox As Shape
    Dim textBoxText As String
    Dim textToChange As TextRange
    textBoxText = "this is some wild text"
    With ActiveWindow.Selection.SlideRange
        Set MyTextBox = .Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                        Left:=153, Top:=50, Width:=400, Height:=100)
        MyTextBox.TextFrame.TextRange.Text = textBoxText
        MyTextBox.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter
        MyTextBox.TextFrame.TextRange.Font.Bold = msoTrue
        MyTextBox.TextFrame.TextRange.Font.Name = "Arial (Headings)"

        # here's where the magic happens
        Set textToChange = MyTextBox.TextFrame.TextRange
        textToChange.Words(3).Select
        textToChange.Words(3).Font.Size = 42

    End With
End Sub

不需要RichTextBox。答案在于TextBox的TextFrame中TextRange对象的属性(真是太多了!)。基本上,您可以分析/遍历此范围对象内的文本,如果您根据段落(或句子、单词、字符等)进行选择,则可以应用不同的文本效果

Sub CreateTextbox()
    Dim MyTextBox As Shape
    Dim textBoxText As String
    Dim textToChange As TextRange
    textBoxText = "this is some wild text"
    With ActiveWindow.Selection.SlideRange
        Set MyTextBox = .Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                        Left:=153, Top:=50, Width:=400, Height:=100)
        MyTextBox.TextFrame.TextRange.Text = textBoxText
        MyTextBox.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter
        MyTextBox.TextFrame.TextRange.Font.Bold = msoTrue
        MyTextBox.TextFrame.TextRange.Font.Name = "Arial (Headings)"

        # here's where the magic happens
        Set textToChange = MyTextBox.TextFrame.TextRange
        textToChange.Words(3).Select
        textToChange.Words(3).Font.Size = 42

    End With
End Sub

不需要RichTextBox。答案在于TextBox的TextFrame中TextRange对象的属性(真是太多了!)。基本上,您可以分析/遍历此范围对象内的文本,如果您根据段落(或句子、单词、字符等)进行选择,则可以应用不同的文本效果

Sub CreateTextbox()
    Dim MyTextBox As Shape
    Dim textBoxText As String
    Dim textToChange As TextRange
    textBoxText = "this is some wild text"
    With ActiveWindow.Selection.SlideRange
        Set MyTextBox = .Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                        Left:=153, Top:=50, Width:=400, Height:=100)
        MyTextBox.TextFrame.TextRange.Text = textBoxText
        MyTextBox.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter
        MyTextBox.TextFrame.TextRange.Font.Bold = msoTrue
        MyTextBox.TextFrame.TextRange.Font.Name = "Arial (Headings)"

        # here's where the magic happens
        Set textToChange = MyTextBox.TextFrame.TextRange
        textToChange.Words(3).Select
        textToChange.Words(3).Font.Size = 42

    End With
End Sub

不需要RichTextBox。答案在于TextBox的TextFrame中TextRange对象的属性(真是太多了!)。基本上,您可以分析/遍历此范围对象内的文本,如果您根据段落(或句子、单词、字符等)进行选择,则可以应用不同的文本效果

Sub CreateTextbox()
    Dim MyTextBox As Shape
    Dim textBoxText As String
    Dim textToChange As TextRange
    textBoxText = "this is some wild text"
    With ActiveWindow.Selection.SlideRange
        Set MyTextBox = .Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                        Left:=153, Top:=50, Width:=400, Height:=100)
        MyTextBox.TextFrame.TextRange.Text = textBoxText
        MyTextBox.TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignCenter
        MyTextBox.TextFrame.TextRange.Font.Bold = msoTrue
        MyTextBox.TextFrame.TextRange.Font.Name = "Arial (Headings)"

        # here's where the magic happens
        Set textToChange = MyTextBox.TextFrame.TextRange
        textToChange.Words(3).Select
        textToChange.Words(3).Font.Size = 42

    End With
End Sub

获取文本范围引用,然后指定所需的字体大小

With myTextBox.TextFrame2.TextRange
    With .InsertAfter("This text should be of font size 24,")
        .Font.Size = 24
    End With
    With .InsertAfter("this text should be of font size 20")
        .Font.Size = 20
    End With
End With

获取文本范围引用,然后指定所需的字体大小

With myTextBox.TextFrame2.TextRange
    With .InsertAfter("This text should be of font size 24,")
        .Font.Size = 24
    End With
    With .InsertAfter("this text should be of font size 20")
        .Font.Size = 20
    End With
End With

获取文本范围引用,然后指定所需的字体大小

With myTextBox.TextFrame2.TextRange
    With .InsertAfter("This text should be of font size 24,")
        .Font.Size = 24
    End With
    With .InsertAfter("this text should be of font size 20")
        .Font.Size = 20
    End With
End With

获取文本范围引用,然后指定所需的字体大小

With myTextBox.TextFrame2.TextRange
    With .InsertAfter("This text should be of font size 24,")
        .Font.Size = 24
    End With
    With .InsertAfter("this text should be of font size 20")
        .Font.Size = 20
    End With
End With

我相信您需要使用一个RichTextBox或两个文本框来实现此目的。我相信您需要使用一个RichTextBox或两个文本框来实现此目的。我相信您需要使用一个RichTextBox或两个文本框来实现此目的。我相信您需要使用一个RichTextBox或两个文本框来实现此目的。