首页 > 解决方案 > 宏从 Excel 向 PowerPoint 发送请求:代码在我的计算机上工作,而不是在用户的计算机上

问题描述

我的代码从 Excel 调用 PowerPoint 并使用电子表格中的数据创建幻灯片。该代码适用于我的计算机,但用户收到错误 1004。

我曾尝试使用其他人以前开发的另一个代码。这个:https ://www.thespreadsheetguru.com/blog/2014/3/17/copy-paste-an-excel-range-into-powerpoint-with-vba

由于某些原因,此代码再次适用于我的计算机,但不适用于用户的计算机。它会在某些选项卡上导致系统错误 400,但它适用于 1 个选项卡。

Sub CopyRangeToPresentationTot()
'Step 1: Declare your variables
  Dim PP As PowerPoint.Application
  Dim PPPres As PowerPoint.Presentation
  Dim PPSlide As PowerPoint.Slide
  Dim SlideTitle As String
'Step 2: Open PowerPoint and create new presentation
  Set PP = New PowerPoint.Application
  Set PPPres = PP.Presentations.Add
  PP.Visible = True
'Step 3: Add new slide as slide 1 and set focus to it
  Set PPSlide = PPPres.Slides.Add(1, ppLayoutTitleOnly)
  PPSlide.Select
'Step 4: Copy the range as a picture
  Sheets(ActiveSheet.Name).Range("B2:F18").CopyPicture _
  Appearance:=xlScreen, Format:=xlPicture
'Step 5: Paste the picture and adjust its position
  PPSlide.Shapes.Paste.Select
  PP.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
  PP.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

'Step 7: Memory Cleanup
  PP.Activate
  Set PPSlide = Nothing
  Set PPPres = Nothing
  Set PP = Nothing
End Sub

我希望我的代码将创建一张幻灯片,其中包含 Excel 中的范围作为图片。用户遇到 1004 错误。

标签: excelvbapowerpoint

解决方案


推荐阅读