1

Excel セルの値を取得して、PowerPoint テキスト ボックスに入力しようとしています。スプレッドシートは常に変化しており、値が常に同じ行または同じ順序であるとは限らないため、PowerPoint テーブルを Excel スプレッドシートにリンクしたくありません。

だから私はこのVBAコードを書いて、テキストボックスに入力しようとしています. 私は多くの VBA を行ってきましたが、この組み合わせを試みたことはありません。以下は私がこれまでに持っているものです (追加のテキスト ボックスにはさらに多くのコードが配置されますが、最初に 1 つを機能させる必要があります)。オブジェクトが適切に処理されていないことに問題があることは認識していますが、修正方法がわかりません。

Excel と PowerPoint 2007 を使用しています。太字の部分でエラーが表示されます - 438 オブジェクトはこのプロパティまたはメソッドをサポートしていません。

ありがとう!

 Sub valppt()

 Dim PPT As PowerPoint.Application
    Dim newslide As PowerPoint.Slide
    Dim slideCtr As Integer
    Dim tb As PowerPoint.Shape
    Set PPT = CreateObject("PowerPoint.Application")
    PPT.Visible = True

    PPT.Presentations.Open "C:\Documents\createqchart.pptx"

    Range("F2").Activate
    slideCtr = 1

    Set newslide = ActivePresentation.Slides(slideCtr).Duplicate
    Set tb = newslide.Shapes("TextBox1")

    slideCtr = slideCtr + 1
    ' Do Until ActiveCell.Value = ""
    Do Until slideCtr > 2
        If slideCtr = 2 Then
           tb.TextFrame2.TextRange.Characters.Text = ActiveCell.Value
        End If
        ActiveCell.Offset(0, 1).Activate
        slideCtr = slideCtr + 1

        If slideCtr = 38 Then
            Set newslide = PPT.ActivePresentation.Slides(slideCtr).Duplicate
            ActiveCell.Offset(1, -25).Activate
        End If

      Loop

   End Sub

5/17 更新

スライドの複製は機能しますが、テキスト ボックスを評価することはまだできません。テキストボックスに値を割り当てるステートメントの前に、適切な set ステートメントを思いつくことができませんでした。適切なステートメントを取得できていないため、現時点では set ステートメントすらありません。任意の支援をいただければ幸いです。以下が最新のコードです。

Sub shptppt()
'
' shptppt Macro
'

    Dim PPT As PowerPoint.Application
    Dim pres As PowerPoint.Presentation
    Dim newslide As PowerPoint.Slide
    Dim slideCtr As Integer
    Dim tb As PowerPoint.Shape


    Set PPT = CreateObject("PowerPoint.Application")
    PPT.Visible = True

    Set pres = PPT.Presentations.Open("C:\Documents\createqchart.pptx")

    Range("F2").Activate
    slideCtr = 1

    'Set newslide = ActivePresentation.Slides(slideCtr).Duplicate
    ' Set tb = newslide.Shapes("TextBox1")


    pres.Slides(slideCtr).Copy
    pres.Slides.Paste
    Set newslide = pres.Slides(pres.Slides.Count)
    newslide.MoveTo slideCtr + 1

    slideCtr = slideCtr + 1
    ' Do Until ActiveCell.Value = ""
    Do Until slideCtr > 2
        If slideCtr = 2 Then
            tb.Slides.TextFrame2.TextRange.Characters.Text = ActiveCell.Value
        End If
        ActiveCell.Offset(0, 1).Activate
        slideCtr = slideCtr + 1

        If slideCtr = 38 Then
            Set newslide = PPT.ActivePresentation.Slides(slideCtr).Duplicate
            ActiveCell.Offset(1, -25).Activate
        End If

    Loop

End Sub
4

2 に答える 2

1

txtReqBase有効じゃない。コードで変数として宣言されておらず、Powerpoint でサポートされているプロパティ/メソッドではないため、438 エラーが発生します。

図形にテキストを挿入するには、図形を識別してから操作する必要があります.Text。形状変数を使用してこれを行うのが最も簡単だと思います。

'## If you have enabled reference to Powerpoint, then:'
Dim tb As Powerpoint.Shape
'## If you do not enable Powerpoint reference, use this instead'
'Dim tb as Variant '

Set tb = newSlide.Shapes("TextBox1")  '## Update this to use the correct name or index of the shapes collection ##'

tb.TextFrame2.TextRange.Characters.Text = ActiveCell.Value

UPDATE不一致エラー設定についてtb

PPT As ObjectPowerpoint オブジェクト ライブラリへの参照を有効にしていないため、不一致エラーが発生していると考えていますPowerPoint.Application

現在のコードの解釈Dim tb as Shapeは、Powerpoint.Shape ではなく、Excel.Shape を参照しています。

Powerpoint オブジェクト ライブラリへの参照を有効にすると、次のことができます。

Dim PPT as Powerpoint.Application
Dim newSlide as Powerpoint.Slide
Dim tb as Powerpoint.Shape

PPT オブジェクト ライブラリへの参照を有効にしたくない場合、または有効にできない場合は、 または を試してみてDim tb as VariantくださいDim tb as Object

UPDATE 2パワーポイントへの参照を有効にする方法:

VBE で、[ツール] | [ツール] から。参照、マシンでサポートされている PPT バージョンに対応するボックスをオンにします。Excel 2010 では、これは 14.0 です。2007 年には 12.0 だと思います。

PPT オブジェクト ライブラリへの参照を有効にする

アップデート 3

メソッドはDuplicate2007 年には利用できないようです。いずれにせよ、2010 年には奇妙なエラーが発生します。スライドは正しくコピーされますが、変数が設定されていません。

代わりにこれを試してください:

Sub PPTTest()

Dim PPT As PowerPoint.Application
Dim pres As PowerPoint.Presentation
Dim newslide As PowerPoint.Slide
Dim slideCtr As Integer
Dim tb As PowerPoint.Shape

Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True


'Control the presentation with a variable
Set pres = PPT.Presentations.Open("C:\users\david_zemens\desktop\Presentation1.pptx")

Range("F2").Activate
slideCtr = 1

'## This only works in 2010/2013 ##
'pres.Slides(slideCtr).Duplicate

'## Use this method in Powerpoint 2007 (hopefully it works)
pres.Slides(slideCtr).Copy
pres.Slides.Paste
Set newslide = pres.Slides(pres.Slides.Count)
newslide.MoveTo slideCtr + 1
...
于 2013-05-16T15:16:37.930 に答える
0

テキストボックスから ActiveX コントロールのテキストボックスに切り替えたことを忘れていました。ここに正しいコードがあります。

valppt()
Dim PPT As PowerPoint.Application
Dim newslide As PowerPoint.SlideRange
Dim slideCtr As Integer
Dim tb As PowerPoint.Shape
Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True

PPT.Presentations.Open ("C:\Documents\createqchart.pptx")

Range("F2").Activate
slideCtr = 1

Set newslide = PPT.ActivePresentation.Slides(slideCtr).Duplicate
Set tb = newslide.Shapes("TextBox" & slideCtr)

slideCtr = slideCtr + 1
Do Until ActiveCell.Value = ""
'Do Until slideCtr > 2
    If slideCtr = 2 Then
       tb.OLEFormat.Object.Value = Format(ActiveCell.Value, "m/d/yyyy")
    End If
    ActiveCell.Offset(0, 1).Activate
    slideCtr = slideCtr + 1

    If slideCtr = 38 Then
        Set newslide = PPT.ActivePresentation.Slides(slideCtr).Duplicate
        ActiveCell.Offset(1, -25).Activate
    End If

Loop
End Sub
于 2013-05-17T20:14:17.917 に答える