在VBA中更改文本框的颜色(明暗处理/颜色渐变)

在VBA中更改文本框的颜色(明暗处理/颜色渐变),vba,gradient,powerpoint,backcolor,Vba,Gradient,Powerpoint,Backcolor,我试图在VBA中的PowerPoint演示文稿开头插入自动摘要。(我对Visual Basic相当陌生) 我已经找到了给我参考的代码,但我似乎无法计算出一个形状的颜色梯度 With ActivePresentation.Slides(1) .Shapes(1).Fill.Visible = msoTrue .Shapes(1).Fill.ForeColor.RGB = RGB(208, 30, 60) .Shapes(1).Fill.BackColor.RGB = RGB(97, 18, 30)

我试图在VBA中的PowerPoint演示文稿开头插入自动摘要。(我对Visual Basic相当陌生)

我已经找到了给我参考的代码,但我似乎无法计算出一个形状的颜色梯度

With ActivePresentation.Slides(1)
.Shapes(1).Fill.Visible = msoTrue
.Shapes(1).Fill.ForeColor.RGB = RGB(208, 30, 60)
.Shapes(1).Fill.BackColor.RGB = RGB(97, 18, 30)
.Shapes(1).Fill.TwoColorGradient msoGradientHorizontal, 2
.Shapes(1).Line.Visible = msoFalse
互联网上的医生说这种方法是前向色和后向色,但我似乎无法让它工作。我不明白为什么第二种颜色是白色而不是RGB代码所说的深红色

我当前的模板的标题在侧面,垂直文本在右侧。文本框以270°的角度从RGB(208、30、60)到RGB(97、18、30)线性着色

这是由完整的VBA代码给出的(在末尾)

这是我想要的(数字如VBA幻灯片所示)

完整代码:

Sub Sommaire()
Dim Diapo As Slide
Dim titre As Shape
Dim petit_titre As Shape
Dim texte_ajout As TextRange
Dim texte_sommaire As TextRange
Dim ligne_sommaire As TextRange
Dim y As Byte
'Si le titre de la première diapo est "Sommaire", elle sera supprimée
'cela permet de relancer la macro autant de fois que l'on souhaite
'sans avoir à supprimer la diapo de sommaire
If ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange = "SOMMAIRE" Then
ActivePresentation.Slides(1).Delete
End If
' ajoute une diapo en début de présentation avec
'la disposition de mise en titre n°2 du masque
ActivePresentation.Slides.Add Index:=1, Layout:=ppLayoutText

With ActivePresentation.Slides(1)
.Shapes(1).TextFrame.TextRange = "SOMMAIRE"
.Shapes(1).TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
.Shapes(1).TextFrame.TextRange.Font.Name = "Arial Black"
.Shapes(1).TextFrame.TextRange.Font.Size = 24
.Shapes(1).TextFrame2.TextRange.Font.Spacing = 3


.Shapes(1).TextFrame2.VerticalAnchor = msoAnchorBottom
.Shapes(1).TextFrame2.TextRange.ParagraphFormat.Alignment = _
        msoAlignLeft

.Shapes(1).TextFrame2.MarginLeft = 14.1732283465
.Shapes(1).TextFrame2.MarginRight = 14.1732283465
.Shapes(1).TextFrame2.MarginTop = 14.1732283465
.Shapes(1).TextFrame2.MarginBottom = 28.3464566929
.Shapes(1).TextFrame2.WordWrap = msoTrue
.Shapes(1).TextFrame.Orientation = msoTextOrientationUpward
.Shapes(1).Left = 0 * 72
.Shapes(1).Top = 0 * 72
.Shapes(1).Height = ActivePresentation.PageSetup.SlideHeight
.Shapes(1).Width = 0.975 * 72

.Shapes(1).Fill.Visible = msoTrue
.Shapes(1).Fill.ForeColor.RGB = RGB(208, 30, 60)
.Shapes(1).Fill.BackColor.RGB = RGB(97, 18, 30)
.Shapes(1).Fill.TwoColorGradient msoGradientHorizontal, 2
.Shapes(1).Line.Visible = msoFalse

.Shapes(1).Shadow.Type = msoShadow25
.Shapes(1).Shadow.Visible = msoTrue
.Shapes(1).Shadow.Style = msoShadowStyleInnerShadow
.Shapes(1).Shadow.Blur = 5
.Shapes(1).Shadow.OffsetX = 3.9993907806
.Shapes(1).Shadow.OffsetY = -0.0698096257
.Shapes(1).Shadow.ForeColor.RGB = RGB(52, 9, 16)
.Shapes(1).Shadow.Transparency = 0.5


Set texte_ajout = .Shapes(2).TextFrame.TextRange
End With

With ActivePresentation.Slides(1).Shapes _
     .AddShape(msoShapeRectangle, 1.5275 * 72, 32.7, 180, 29.1)
    .TextFrame.TextRange.Text = "Sommaire"
    .TextFrame.MarginBottom = 10
    .TextFrame.MarginLeft = 10
    .TextFrame.MarginRight = 10
    .TextFrame.MarginTop = 10
    .TextFrame.TextRange.Font.Name = "Arial Black"
    .TextFrame.TextRange.Font.Size = 18
    .TextFrame2.VerticalAnchor = msoAnchorMiddle
        .TextFrame2.TextRange.ParagraphFormat.Alignment = _
        msoAlignLeft
    .Fill.Visible = msoFalse
    .Line.Visible = msoFalse
    .TextFrame2.TextRange.Characters(1, 1).Font.Fill.ForeColor.RGB = RGB(208, 30, 60)
    .TextFrame2.TextRange.Characters(2, 7).Font.Fill.ForeColor.RGB = RGB(39, 39, 39)
    .Shadow.Visible = msoFalse

    End With







'boucle sur toutes les diapos à partir de la 2e
For y = 2 To ActivePresentation.Slides.Count
Set Diapo = ActivePresentation.Slides(y)
'si la diapo a un titre
If Diapo.Shapes.HasTitle Then
Set titre = Diapo.Shapes.Title
texte_ajout = texte_ajout & Format(y, "0 - ") & titre.TextFrame. _
TextRange.Text & Chr(13) & vbCrLf
End If
Next y
'ajout de liens aux items du sommaire
Set texte_sommaire = _
ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange
texte_sommaire.Font.Size = 20
texte_sommaire.Font.Color.RGB = RGB(39, 39, 39)

With ActivePresentation.Slides(1).Shapes(2)
.Left = 1.5275 * 72
.Top = 1.9 * 72
End With

End Sub

提前感谢您

我从Excel宏记录器中选择了它,因为形状和大多数对象在Office应用程序之间仍然有许多公用部分

ActiveSheet.Shapes.Range(Array("TextBox 1")).Select
With Selection.ShapeRange
    With .Fill
        .ForeColor.RGB = RGB(255, 0, 0)
        .BackColor.RGB = RGB(0, 0, 1)
        .TwoColorGradient msoGradientHorizontal, 1
        .RotateWithObject = msoTrue
        .Visible = msoTrue
    End With
    With .TextFrame2.TextRange.Font
        .BaselineOffset = 0
        .Spacing = 1.6
    End With
End With

您只需将它“附加”(替换
选项
)到您的文本框中,但我认为您可以处理它。我将编辑我的答案,将我在评论中给你的所有提示也包括在内。

早上好。我使用对象浏览器(在VBEditor中按F2键):
ActivePresentation.Slides(1).Shapes(2).TextFrame.Orientation=msoTextOrientationVerticalFarEast
msoTextOrientationVerticalFarEast
(所有常量都列在`msoTextOrientation`)而“bidouiller”使用代码时,我发现Orientation命令,我将它与
msoTextOrientationUpward
一起使用,这给了我想要的方向,但我得到了一个大的方形。对于颜色,我尝试使用excel和“录制宏”来获得我想要的代码。你知道我怎样才能使文本框适合幻灯片的高度吗非常感谢您在PowerPoint VBE中查看对象浏览器(按F2键)并查看幻灯片类和形状类,但我想这两个类都有
高度
宽度
属性,因此我认为类似的内容会很有用:
形状(2)。高度=幻灯片(1)。高度
@R3uK我使用的
.Shapes(1).Height=ActivePresentation.PageSetup.SlideHeight以获得正确的高度。我试着贴一张我现在所在的位置的照片,我有正确的位置,我只有间隔和侧框的颜色。谢谢你的帮助。嗨,这也是我使用的方法。我在开始录制宏后定义了框。我切换了
twocolorgradient
的顺序,因此现在是在
forecolor
backcolor
之前(我意识到顺序可能很重要),我得到了我想要的东西。但是谢谢你。好的,很高兴你找到了这样做的方法!稍后我将改进我的答案,但只是为了澄清,我有一个关于
TwoColorGradient
方法的第二个参数的问题。您建议将
2
改为
Gradient
,您理解该参数的含义吗?我仍然对这一点感到困惑(不是戏剧性的),这是梯度的位置。2具有围绕顶部中间的渐变。3在中间有梯度。1在底部中间有梯度。在我的例子中,2使红色从下到上变暗,1则相反。好的,谢谢你的解释!;)博恩·乔伊!(顺便说一句,你能投票给我的答案吗,我正在制作我的精炼厂徽章,它会帮助我:)没问题:)没有pb,pas de soucis!完成!