[英]Exporting data from Excel to an existing PowerPoint slide using VBA
我正在為一些簡單的數據分析編寫一個小的excel插件,但不幸的是我不是VBA程序員;)
到目前為止我做了什么:
我接下來想做什么:
我認為可以在幻燈片中定義某種文本框,然后將值放入其中......還沒找到任何東西!
對此有任何幫助表示贊賞;)
這是excel&powerpoint 2007,但我希望盡可能獨立於版本。
TIA
這是我在Mahipal Padigela的VBA網站上找到的一些代碼
(它也在StackOverFlow上引用)
''# Code by Mahipal Padigela
''# Open Microsoft Powerpoint,Choose/Insert a Table type Slide(No.4), then double click to add a...
''# ...Table(3 Cols & 2 Rows) then rename the Table to "Table1", Save and Close the Presentation
''# Open Microsoft Excel, add some test data to Sheet1(This example assumes that you have some data in...
''# ... Rows 1,2 and Columns 1,2,3)
''# Open VBA editor(Alt+F11),Insert a Module and Paste the following code in to the code window
''# Reference 'Microsoft Powerpoint Object Library' (VBA IDE-->tools-->references)
''# Change "strPresPath" with full path of the Powerpoint Presentation created earlier.
''# Change "strNewPresPath" to where you want to save the new Presnetation to be created later
''# Close VB Editor and run this Macro from Excel window(Alt+F8)
Dim oPPTApp As PowerPoint.Application
Dim oPPTShape As PowerPoint.Shape
Dim oPPTFile As PowerPoint.Presentation
Dim SlideNum As Integer
Sub PPTableMacro()
Dim strPresPath As String, strExcelFilePath As String, strNewPresPath As String
strPresPath = "H:\PowerPoint\Presentation1.ppt"
strNewPresPath = "H:\PowerPoint\new1.ppt"
Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath)
SlideNum = 1
oPPTFile.Slides(SlideNum).Select
Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("Table1")
Sheets("Sheet1").Activate
with oPPTShape.Table
.Cell(1, 1).Shape.TextFrame.TextRange.Text = Cells(1, 1).Text
.Cell(1, 2).Shape.TextFrame.TextRange.Text = Cells(1, 2).Text
.Cell(1, 3).Shape.TextFrame.TextRange.Text = Cells(1, 3).Text
.Cell(2, 1).Shape.TextFrame.TextRange.Text = Cells(2, 1).Text
.Cell(2, 2).Shape.TextFrame.TextRange.Text = Cells(2, 2).Text
.Cell(2, 3).Shape.TextFrame.TextRange.Text = Cells(2, 3).Text
end with
oPPTFile.SaveAs strNewPresPath
oPPTFile.Close
oPPTApp.Quit
Set oPPTShape = Nothing
Set oPPTFile = Nothing
Set oPPTApp = Nothing
MsgBox "Presentation Created", vbOKOnly + vbInformation
End Sub
這里有一些關於使用VBA自動化Powerpoint的額外幫助和http://www.mahipalreddy.com/vba/ppvba.htm
獲取單個幻燈片的名稱嘗試如下所示:
Dim oSlide As Slide
For Each oSlide In ActiveWindow.Presentation.Slides
Debug.Print oSlide.Name
Next
End Sub
應該能為你指明正確的方向! (所以可笑)
菲利普
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.