首页 > 解决方案 > 在 VBA 中从两个不同的 excel 文件创建 PPT

问题描述

我正在尝试打开一个excel文件,将范围作为图片并创建一个ppt。我不确定下面的代码出了什么问题。有人可以帮忙吗?该代码适用于来自其他 excel 文件的所有其他幻灯片。我打开一个excel文件并切换的那一刻,它抛出“下标超出范围错误”

Sub GlobalBankPPT()
 Dim ppApp As PowerPoint.Application
 Dim ppPres As PowerPoint.Presentation
 Dim ppSlide As PowerPoint.Slide
 Dim ppShape As PowerPoint.Shape
 Dim ppPic As Variant
 Dim j As Integer
 Dim wkb As Workbook
 Dim sh As Worksheet
 Dim WS_Count As Integer, i As Integer
 Dim mypp As New ExcelToPPt.cPPt

 mypp.InitFromTemplate MyTemplateppt:=mytemp, MyOutputppt:=""

 Set ppApp = GetObject(, "PowerPoint.Application")
 ppApp.Visible = msoTrue
 Set ppPres = ppApp.ActivePresentation


Set wkb = Workbooks.Open(Filename:=ThisWorkbook.Worksheets("Index").Range   ("FilePath"))
wkb.Activate

WS_Count = wkb.Worksheets.Count

For i = 1 To WS_Count
    If Worksheets(i).Name = "Industry" Then
        wkb.Activate
        Set sh = ActiveSheet
        Exit For

 End If
Next I

'--------------------------------------------------------------------Slide7
 Range(Sheet15.Range("A150"), Sheet15.Range("Q191")).Select
 Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
 ppPres.Slides(7).Select
 Set ppPic = ppPres.Slides(7).Shapes.Paste

 ppPic.Select
 ppPic.Top = 70.24
 ppPic.Width = 10.5 * 100
 ppPic.Height = ppPic.Width / 3.4
 ppPic.Left = 50

end sub

标签: excelvbapowerpoint

解决方案


推荐阅读