我正在尝试创建一个excel宏来复制Excel工作表上显示的图表,并将它们粘贴(粘贴特殊)到PowerPoint中.我遇到的问题是如何将每个图表粘贴到不同的幻灯片上?我根本不知道语法..
这是我到目前为止(它的工作原理,但它只粘贴到第一张表):
Sub graphics3()
Sheets("Chart1").Select
ActiveSheet.ChartObjects("Chart1").Activate
ActiveChart.ChartArea.Copy
Sheets("Graphs").Select
range("A1").Select
ActiveSheet.Paste
With ActiveChart.Parent
.Height = 425 ' resize
.Width = 645 ' resize
.Top = 1 ' reposition
.Left = 1 ' reposition
End With
Dim PPT As Object
Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True
PPT.Presentations.Open Filename:="locationwherepptxis"
Set PPApp = GetObject("Powerpoint.Application")
Set PPPres = PPApp.activepresentation
Set PPSlide = PPPres.slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
' Copy chart as a picture
ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _
Format:=xlPicture
' Paste chart
PPSlide.Shapes.Paste.Select
' Align pasted chart …Run Code Online (Sandbox Code Playgroud) 我有一段很不错的代码,可以从Excel文件中复制一个范围并将其粘贴到PowerPoint中的activeslide上。经过数小时的尝试,将excel的范围粘贴为表格(没有图像),我发现以下代码可以成功工作。注意:myPP = PowerPoint应用程序。
myPP.CommandBars.ExecuteMso "PasteExcelTableSourceFormatting"
myPP.CommandBars.ReleaseFocus
Run Code Online (Sandbox Code Playgroud)
问题在于,当我执行宏时,将粘贴表,但是除非逐步执行代码,否则vba无法识别该表。我已经使用以下代码对此进行了测试。在执行过程中,将完全跳过代码,但在逐步执行过程中将触发该代码。
For Each shp In activeSlide.Shapes
If shp.HasTable Then
MsgBox shp.Name
End If
Next
Run Code Online (Sandbox Code Playgroud)
下面是完整的代码。基本上,我只是希望将excel范围作为表格粘贴到我的Powerpoint中,并希望将该表格扩展为适合幻灯片。我愿意提出一些修改建议。谢谢你的帮助
Dim myPP as Object
Dim activeSlide as Object
Dim shp as Object
Worksheets("Sheet2").Activate
Worksheets("Sheet2").Range(Cells(1,1), Cells(4,7)).Copy
Worksheets("Sheet1").Activate
myPP.CommandBars.ExecuteMso "PasteExcelTableSourceFormatting"
myPP.CommandBars.ReleaseFocus
Dim myTable As String
For Each shp In activeSlide.Shapes
If shp.HasTable Then
MsgBox shp.Name
myTable = shp.Name
End If
Next
With activeSlide.Shapes(myTable)
.Left = 23
.Top = 105
.Width = 650
.Height = 375
End With
Run Code Online (Sandbox Code Playgroud)
对于ASH
Dim myPP As …Run Code Online (Sandbox Code Playgroud)