首页 > 解决方案 > 你如何创建一个黄色的文本框?

问题描述

你如何创建一个黄色的文本框?

我尝试了下面的方法,但我不能这样做 a) 它在活动幻灯片中执行它,b) 它是黄色的(可能带有一些格式作为阴影)谢谢

Sub sticky()
Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=100, Top:=100, Width:=200, Height:=50).TextFrame _
.TextRange.Text = "Test Box"
End Sub

标签: vbapowerpoint

解决方案


使用 ActiveWindow.Selection.SlideRange(1) 而不是 ActivePresentation.Slides(1) 通常会为您提供所需的幻灯片参考。

初学者试试这个:

Sub sticky()
' Use object variables for slide and shape
Dim oSl as Slide
Dim oSh as Shape

' Get a reference to the current slide
Set oSl = ActiveWindow.Selection.SlideRange(1)

' Add the shape and get a reference to it:
Set oSh = oSl.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=100, Top:=100, Width:=200, Height:=50)

With oSh
  .TextFrame.TextRange.Text = "Test Box"
  .Fill.ForeColor.RGB = RGB(255, 255, 0)
  ' Add any other formatting to the shape here 
End With  ' oSh ... the shape you added

End Sub 

推荐阅读