Excel VBAで更新する必要のあるPowerPointプレゼンテーションがあり、チャート内のデータシートにデータを追加しようとしています。コードの下に。これを行うには、Excel VBAでPowerPointプレゼンテーションを開き、Excelが開いていることを前提にしてそこから範囲をとり、DataChartに貼り付けます。Excel VBAでPowerPointデータシートのチャートオブジェクトを編集する
私はまだオブジェクトにかなり新しいですが、PowerPointオブジェクトにはまだまだ多く、そこに貼り付ける方法はわかりません。オブジェクトはmsoEmbeddedOLEObjectであり、OLEFormat.progIDは "MSGraph.Chart.8"であり、悲しいことに私は理解しません。
Public sPath As String, sFile As String, sFilePPT As String
Public PPApp As PowerPoint.Application
Public PPPres As PowerPoint.Presentation
Public PPSlide As PowerPoint.Slide
Public PPShape As PowerPoint.Shape
Public PPChart As PowerPoint.Chart
Public PPChartData As PowerPoint.ChartData
Public cTable As Excel.ListObject
Sub OpenPPT()
sPath = ThisWorkbook.Path & "\"
sFilePPT = "Presentation1.pptx"
On Error Resume Next
'==> Check if PowerPoint is running
Set PPApp = GetObject(, "PowerPoint.Application")
If PPApp Is Nothing Then
'==> If PowerPoint is not running, create new instance
Set PPApp = CreateObject("PowerPoint.Application")
'==> and make it visible (PowerPoint must be visible to be used)
PPApp.Visible = True
Set PPPres = PPApp.Presentations.Open(sPath & sFilePPT)
End If
On Error GoTo 0
'==> Reference presentation and slide
On Error Resume Next
'==> If there's at least one presentation, use it
If PPApp.Windows.Count > 0 Then
Set PPPres = PPApp.ActivePresentation
'==> use active slide
Set PPSlide = PPPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
Else
MsgBox "PowerPoint Presentation not found"
Exit Sub
End If
On Error GoTo 0
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub
Sub test()
Dim i As Byte
Dim r As Range
Call OpenPPT
Set PPApp = GetObject(, "PowerPoint.Application")
Set PPPres = PPApp.Presentations(1)
Debug.Print PPPres.Name
Set PPSlide = PPPres.Slides(2)
PPSlide.Select
Debug.Print PPSlide.Name
Set PPShape = PPSlide.Shapes(2)
PPShape.Select
If PPShape.OLEFormat.progID = "MSGraph.Chart.8" Then
Set r = Workbooks("Budget_CM11.xlsm").Worksheets("Recap").Range("AQ12:AY17")
r.Copy
'==> I see it opens the DataChart of the Chart for editing
PPShape.OLEFormat.DoVerb 2
'code needed here that should copy the Excel range
'within the PowerPoint Object (Chart?) Data
End If
End Sub
あなたは[リンクオブジェクト]などでグラフを貼り付けることはできません(https://www.google.co.uk/search?q=embedding+excel+chart+ + powerpoint&oq = Embedding + Excel + Chart +&aqs = chrome.1.69i57j0l4.6352j1j4&sourceid = chrome&ie = UTF-8)自動的に更新されますか? – QHarr
@QHarr私はそれが現在の問題を解決するだろうと思うが、私はちょっとPowerPointプレゼンテーションを変更せずに更新するだけだ。 – CCM
@QHarr私はフォローしているかどうかはわかりませんが、エクセルVBAとPowerPointの両方でデータを更新する必要があるため、Excel VBAで作業しているプロジェクトをやりたいと思っていました。 – CCM