我有以下代码将excel表格导出到powerpoint . 在每个工作表中,它从单元格A1和A2获取范围,并将范围复制到powerpoint中 .
现在我想添加两个函数,但我不知道如何做到这一点,所以我希望有人可以帮我这个?
1 - 在只包含一个表的工作表中,代码完全按照它应该执行的操作 . 但是在某些工作表中,我已经包含了图片或图表,而这些都未正确粘贴到Excel中 . (仅在powerpoint幻灯片中复制空白图片) . 现在我想创建一个代码,使用我从单元格“C1”输入来确定是否需要将此幻灯片粘贴为图像或普通粘贴 . 我试图解决这个问题,但我的代码不断出错 . 有什么办法可以调整这段代码,这样我就可以使用了吗?
2 - 代码现在复制所有工作表,但我希望它从表7开始并从那里继续直到结束 . 因此跳过前6个工作表 . 有谁知道如何在我的VBA中排除这些表格?
Sub PrintPPT()
'Step 1: Declare variables
Dim pp As Object
Dim PPPres As Object
Dim PPSlide As Object
Dim xlwksht As Worksheet
Dim MyRange As String
'Step 2: Open PowerPoint, add a new presentation and make visible
Set pp = CreateObject("PowerPoint.Application")
Set PPPres = pp.Presentations.Add
pp.Visible = True
'Step 3: Start the loop through each worksheet
For Each xlwksht In ActiveWorkbook.Worksheets
MyRange = xlwksht.Range("A1").Value & ":" & xlwksht.Range("A2").Value
xlwksht.Range(MyRange).Copy
'Step 4: Count slides and add new blank slide as next available slide number
'(the number 12 represents the enumeration for a Blank Slide)
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, 12)
PPSlide.Select
'Step 5: Paste the picture and adjust its position
PPPres.ApplyTemplate ("C:\Users\Template.potx")
Pastetype = xlwksht.Range("C1").Value
' Pastetype will be "PasteSpecial DataType:=2" for images
' Pastetype will be "Paste.Select" for normal
PPSlide.Shapes.pastetype '2 = ppPasteEnhancedMetafile
'pp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
pp.ActiveWindow.Selection.ShapeRange.Top = 85
pp.ActiveWindow.Selection.ShapeRange.Left = 7.2
'pp.ActiveWindow.Selection.ShapeRange.Width = 600
'Step 6: Add the title to the slide then move to next worksheet
Next xlwksht
'Step 7: Memory Cleanup
pp.Activate
Set PPSlide = Nothing
Set PPPres = Nothing
Set pp = Nothing
End Sub