? asked in 電腦與網際網路軟體 · 1 decade ago

用EXCEL VBA 新增PPT文字方塊

各位好,

小弟目前想要用EXCEL的VBA來控制PPT,現在已經可以新增一個PPT檔案了,但仍然不知道如何新增一個PPT文字方塊,並且修改裡面的參數(字型,大小,位置....等等),請各位前輩不吝指導一下,感恩

1 Answer

Rating
  • Anonymous
    1 decade ago
    Favorite Answer

    簡單寫法如下, 有問題再提出 ~

    '引用 : Microsoft PowerPoint X.X Object Library

    Sub Add_PPT_Text()

    Dim PPTA As New PowerPoint.Application

    PPTA.Visible = 1

    Dim PPTF As PowerPoint.Presentation

    Set PPTF = PPTA.Presentations.Add

    Dim Sld As PowerPoint.Slide

    Set Sld = PPTF.Slides.Add(Index:=1, Layout:=ppLayoutText)

    '以下為 PPT 中錄製後修改 ~

    PPTA.ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHorizontal, 167.25, 65.875, 204.125, 28.875).Select

    PPTA.ActiveWindow.Selection.ShapeRange.TextFrame.WordWrap = msoTrue

    With PPTA.ActiveWindow.Selection.TextRange.ParagraphFormat

    .LineRuleWithin = msoTrue

    .SpaceWithin = 1

    .LineRuleBefore = msoTrue

    .SpaceBefore = 0.5

    .LineRuleAfter = msoTrue

    .SpaceAfter = 0

    End With

    PPTA.ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select

    With PPTA.ActiveWindow.Selection.TextRange

    .Text = "123"

    With .Font

    .NameAscii = "Arial"

    .NameFarEast = "新細明體"

    .NameOther = "Arial"

    .Size = 18

    .Bold = msoFalse

    .Italic = msoFalse

    .Underline = msoFalse

    .Shadow = msoFalse

    .Emboss = msoFalse

    .BaselineOffset = 0

    .AutoRotateNumbers = msoTrue

    .Color.SchemeColor = ppForeground

    End With

    End With

    PPTA.ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=4).Select

    PPTA.ActiveWindow.Selection.TextRange.Font.Size = 24

    PPTA.ActiveWindow.Selection.Unselect

    End Sub

    2008-10-03 00:11:45 補充:

    參考檔案 : http://www.funp.net/315277

    2008-10-03 00:19:14 補充:

    這麼快 !?

    果然是 "江湖一點訣, 說穿了不值錢" ~

    ^.^

Still have questions? Get your answers by asking now.