问题描述
我的要求是我有一个包含一些数据的Excel。我想从excel中选择一些数据并打开一个PowerPoint文件,并且
在PowerPoint中创建表并将数据填充到 / p>
现在我已经成功地收集了Excel中通过Excel VBA代码打开PowerPoint文件的数据。
代码用于从Excel打开PowerPoint。
设置objPPT = CreateObject(Powerpoint.application)
objPPT.Visible = True
Dim file As String
file =C:\Heavyhitters_new.ppt
设置pptApp = CreateObject(PowerPoint.Application)
设置pptPres = pptApp.Presentations。打开(文件)
现在,如何从Excel中创建PowerPoint中的表并填充数据。 / p>
及时帮助将非常感激。
提前感谢
这里是一些
''#代码由Mahipal Padigela
''#打开Microsoft Powerpoint,选择/插入表格类型幻灯片(No.4),然后双击添加...
''#...表(3 Cols& ; 2行)然后将表重命名为Table1,保存并关闭演示文稿
'打开Microsoft Excel,将一些测试数据添加到Sheet1(此示例假设您有一些数据...
#...行1,2和列1,2,3)
'打开VBA编辑器(Alt + F11),插入模块并将以下代码粘贴到代码窗口
''#引用Microsoft Powerpoint对象库(VBA IDE - >工具 - >引用)
''#使用之前创建的Powerpoint Presentation的完整路径更改strPresPath。
''#将strNewPresPath更改为要保存要稍后创建的新的预定义的位置
'关闭VB编辑器并从Excel窗口运行此宏(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\\\
ew1.ppt
设置oPPTApp = CreateObject(PowerPoint.Application)
oPPTApp.Visible = msoTrue
设置oPPTFile = oPPTApp.Presentations.Open(strPresPath)
SlideNum = 1
oPPTFile.Slides(SlideNum)。选择
设置oPPTShape = oPPTFile.Slides(SlideNum)。形状(Table1)
表单(Sheet1)。激活
oPPTShape.Table.Cell(1,1).Shape.TextFrame.TextRange.Text = Cells(1, 1).Text
oPPTShape.Table.Cell(1,2).Shape.TextFrame.TextRange.Text = Cells(1,2).Text
oPPTShape.Table.Cell(1,3)。 Shape.TextFrame.TextRange.Text = Cells(1,3).Text
oPPTShape.Table.Cell(2,1).Shape.TextFrame.TextRange.Text = Cells(2,1).Text
oPPTShape.Table.Cell(2,2).Shape.TextFrame.TextRange.Text = Cells(2,2).Text
oPPTShape.Table.Cell(2,3).Shape.TextFrame.TextRange.Text =单元格(2,3).Text
oPPTFile.SaveAs strNewPresPath
oPPTFile.Close
oPPTApp.Quit
设置oPPTShape =没有
设置oPPTFile = Nothing
设置oPPTApp = Nothing
MsgBoxPresentation Created,vbOKOnly + vbInformation
End Sub
My requirement is I have a Excel which contains some data. I would like to select some data from the excel and open a PowerPoint file and
Create Table in PowerPoint and populate the data in to it
Right now I have succeeded in collecting the data from excel opening a PowerPoint file through Excel VBA Code.
Code for Opening the PowerPoint from Excel.
Set objPPT = CreateObject("Powerpoint.application")
objPPT.Visible = True
Dim file As String
file = "C:\Heavyhitters_new.ppt"
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPres = pptApp.Presentations.Open(file)
Now how do I create the table in PowerPoint from Excel and populate the data.
Timely help will be very much appreciated.
Thanks in advance,
Here's some code from http://mahipalreddy.com/vba.htm
''# 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
oPPTShape.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = Cells(1, 1).Text
oPPTShape.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = Cells(1, 2).Text
oPPTShape.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = Cells(1, 3).Text
oPPTShape.Table.Cell(2, 1).Shape.TextFrame.TextRange.Text = Cells(2, 1).Text
oPPTShape.Table.Cell(2, 2).Shape.TextFrame.TextRange.Text = Cells(2, 2).Text
oPPTShape.Table.Cell(2, 3).Shape.TextFrame.TextRange.Text = Cells(2, 3).Text
oPPTFile.SaveAs strNewPresPath
oPPTFile.Close
oPPTApp.Quit
Set oPPTShape = Nothing
Set oPPTFile = Nothing
Set oPPTApp = Nothing
MsgBox "Presentation Created", vbOKOnly + vbInformation
End Sub
这篇关于EXcel VBA:Excel宏在PowerPoint中创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!