2016-12-01 18 views
0

私は、PowerPointプレゼンテーションを作成し、スプレッドシートからデータをコピーし、タイトルとテキストボックスを追加するマクロを作成しています。私はデータとタイルを追加してフォーマットすることができましたが、私はテキストボックスを追加するのに苦労しています。下のコードを実行すると、「ActiveXコンポーネントはオブジェクトを作成できません」というエラーが返されます。私は何かを探しているような気がする。どんな助けでも大歓迎です! (最初の '-------'の後の行にエラーが発生します)vbaを使用してPowerPointプレゼンテーションにテキストボックスを追加する方法

Sub Create_Presentation() 

Dim rng As Range 
Dim PowerPointApp As PowerPoint.Application 
Dim myPresentation As PowerPoint.Presentation 
Dim mySlide As PowerPoint.Slide 
Dim myShape As PowerPoint.Shape 
Dim myTextbox As Shape 


On Error Resume Next 


    Set PowerPointApp = CreateObject(class:="PowerPoint.Application") 

    Err.Clear 

    If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application") 


    If Err.Number = 429 Then 
    MsgBox "PowerPoint could not be found, aborting." 
    Exit Sub 
    End If 

    On Error GoTo 0 


    Application.ScreenUpdating = True 


    Set myPresentation = PowerPointApp.Presentations.Add 

    Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly 

Set rng = Range("PL_Tot") 
rng.Copy 

    mySlide.Shapes.PasteSpecial DataType:=xlBitmap 
    Set myShape = mySlide.Shapes(mySlide.Shapes.Count) 


    myShape.Left = 0.3 
    myShape.Top = 67 

    myShape.Width = 430 
    myShape.Height = 406.4 

mySlide.Shapes.Title.TextFrame.TextRange.Text = Range("TotalTitle").Value 

Set sldTitle = mySlide.Shapes.Title 

With sldTitle 
With .TextFrame.TextRange 
With .Font 
.Bold = msoTrue 
.Size = 22 
.Color = RGB(0, 0, 200) 
End With 
End With 
End With 

sldTitle.Top = -30 
'------------------------------------ 

Set myPresentation = ActivePresentation 

Set mySlide = myPresentation.Slides(1) 

Set myTextbox = mySlide.Shapes.AddTextbox(msoTextOrientationHorizontal, _ 
    Left:=0, Top:=10, Width:=200, Height:=50) 

With myTextbox.TextFrame.TextRange 
    .Text = Range("PPTextbox").Value 
    With .Font 
     .Size = 12 
     .Name = "Arial" 
    End With 
End With 

'----------------------------------- 
PowerPointApp.Visible = True 
PowerPointApp.Activate 


Application.CutCopyMode = False 

答えて

1

ExcelとPowerPointの両方にShapeオブジェクトがあります。あなた:

Dim myTextbox As Shape 

は、Excelシェイプを予期するようにExcelを準備します。

Dim myTextbox As PowerPoint.Shape 

に変更してください。PowerPointのプロパティとメソッドをExcelシェイプに適用しようとすると、Excelが吠えません。

+0

ありがとうございます!今は完璧に動作します。新しいことは単純なものになるだろう。 –

関連する問題