|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 caitjcai 于 2020-9-1 17:12 编辑
大家好呀,我在excel写了VBA程序,把单元格的内容copy到PPT对应位置上,只copyA1单元格没事,又接着加上了,让它copyB1单元格,PPT就崩溃了,大家能帮忙看看吗?文档在附件,谢谢!- Sub CreatePowerPoint()
- Dim activeSlide As PowerPoint.Slide
- Dim i As Integer
- Dim Model As Object
- Set newPowerPoint = CreateObject("powerpoint.application")
- Set Model = newPowerPoint.Presentations.Open(ThisWorkbook.Path & "\样本.pptx", , , msoTrue)
- For i = 2 To 3
- newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count).Duplicate
- newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count - 1
- Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count - 1)
- On Error Resume Next
- Range("A" & i).Activate
- Worksheets("Sheet1").Range("A" & i).Copy
- newPowerPoint.CommandBars.ExecuteMso "PasteSourceFormatting"
- 'Paste to PowerPoint and position
- activeSlide.Shapes.PasteSpecial DataType:=ppPasteSourceFormatting, DisplayAsIcon:=msoFalse
- 'PowerPointApp.CommandBars.ExecuteMso ("PasteSourceFormatting")
- Set myShapeRange = activeSlide.Shapes(activeSlide.Shapes.Count)
- 'Set position:
- myShapeRange.Left = 450
- myShapeRange.Top = 100
- myShapeRange.Height = 200
- myShapeRange.Width = 400
- 'Clear The Clipboard
- Application.CutCopyMode = False
- Range("B" & i).Activate
- Worksheets("Sheet1").Range("B" & i).Copy
- newPowerPoint.CommandBars.ExecuteMso "PasteSourceFormatting"
- 'Paste to PowerPoint and position
- activeSlide.Shapes.PasteSpecial DataType:=ppPasteSourceFormatting, DisplayAsIcon:=msoFalse
- 'PowerPointApp.CommandBars.ExecuteMso ("PasteSourceFormatting")
- Set myShapeRange = activeSlide.Shapes(activeSlide.Shapes.Count)
- 'Set position:
- myShapeRange.Left = 100
- myShapeRange.Top = 100
- myShapeRange.Height = 200
- myShapeRange.Width = 400
- 'Clear The Clipboard
- Application.CutCopyMode = False
- Next i
- End Sub
复制代码
|
|