Excel VBA到PPT在office 365 64位中不起作用

Excel VBA到PPT在office 365 64位中不起作用,excel,vba,powerpoint,Excel,Vba,Powerpoint,我在所有版本的excel上都使用了下面的代码 -基本上,我创建了一个带有ppt外观的excel工作表,并将工作表范围导出到ppt Excel VBA导出到PPT在office 365 32位之前的所有版本中都可以正常工作 它在365 64位Windows 10操作系统中不起作用 尝试了以下方法 检查参考-使用14,15,16对象库-效果良好 不使用64位-Excel 365 出现错误-“找不到PowerPoint” Sub ExcelRangeToPPT\u new\u now() “准备好

我在所有版本的excel上都使用了下面的代码 -基本上,我创建了一个带有ppt外观的excel工作表,并将工作表范围导出到ppt

Excel VBA导出到PPT在office 365 32位之前的所有版本中都可以正常工作

  • 它在365 64位Windows 10操作系统中不起作用
尝试了以下方法 检查参考-使用14,15,16对象库-效果良好

不使用64位-Excel 365 出现错误-“找不到PowerPoint”

Sub ExcelRangeToPPT\u new\u now()
“准备好了吗
Application.DisplayAlerts=False
Application.ScreenUpdating=False
Application.IgnoreRemoteRequests=True
变暗rng As范围
Dim PowerPointApp作为对象
作为对象的演示文稿
暗mySlide作为对象
模糊我的形状作为物体
'工作表(“S19”)。选择
'从Excel复制范围
Set rng=thiswoolk.ActiveSheet.Range(“A1:q36”)
出错时继续下一步
'PowerPoint是否已打开?
设置PowerPointApp=GetObject(类:=“PowerPoint.Application”)
'清除错误之间的错误
呃,明白了
'如果PowerPoint尚未打开,请打开PowerPoint
如果PowerPointApp为空,则设置PowerPointApp=CreateObject(类:=“PowerPoint.Application”)
'在找不到PowerPoint应用程序时处理
如果错误号=429,则
找不到MsgBox“PowerPoint,正在中止。”
出口接头
如果结束
图纸(“模板”)。选择
Set rng=thiswoolk.ActiveSheet.Range(“A1:q36”)
instfile=“Noattach”
如果ActFileName=False,则
'PowerPointApp.Activate
'PowerPointApp.Presentations.Add
'设置PP_File=PowerPointApp.ActivePresentation
其他的
PowerPointApp.Activate
设置myPresentation=PowerPointApp.Presentations.Open(ActFileName)
如果结束
设置myPresentation=PowerPointApp.Presentations.Add
设置PP_File=PowerPointApp.ActivePresentation
地址:
多芬特
Set rng=thiswoolk.ActiveSheet.Range(“A1:q36”)
PowerPointApp.Visible=True
'创建新的演示文稿
存款准备金率:
呃,明白了
将mySlide=PP_File.Slides.Add(1,12)'11=pplayouttitlony设置为
PP_File.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
使用PP_File.PageSetup
.SlideSize=ppSlideSizeCustom
.滑动宽度=720
.滑动高度=528
.FirstSlideEnumber=1
.SlideOrientation=MSOOOrientationHorizontal
.NotesOrientation=MSOOOrientationVertical
以
收到
mySlide.Shapes.PasteSpecial数据类型:=2'2=ppPasteEnhancedMetafile
设置myShape=mySlide.Shapes(mySlide.Shapes.Count)
'设置位置:
myShape.Left=0
myShape.Top=0
myShape.LockAspectRatio=msoFalse
myShape.HEIGHT=528
myShape.WIDTH=718
如果输入文件“Noattach”,则
作为对象的暗显对象形状
设置objPPTShape=PP_File.Slides(1).Shapes.AddOLEObject(左:=100,顶:=100,宽:=700,高:=300_
文件名:=instfile,DisplayAsIcon:=True)”或使用,文件名:=“E:\Documents and Settings\User\My Documents\abc.xlsm”代替类名,但不能同时使用两者
带长方形
.左=475
.Top=350
以
设置objPPTShape=Nothing
如果结束
PowerPointApp.Visible=True
PowerPointApp.Activate
Application.CutCopyMode=False
PowerPointApp.PageSetup.SlideOrientation=MSOOOrientationHorizontal
sht=sht-1
如果sht=1,则为图纸(“模板”)。选择:转到ttre
instfile=“Noattach”
如果sht=2,则为图纸(“S2”)。选择:转到添加
ttre:
工作表(“主”)。选择
Application.DisplayAlerts=True
Application.ScreenUpdating=True
Application.IgnoreRemoteRequests=False
MsgBox“PPT已成功创建..请在保存前查看..”
出口接头
错误:
Debug.Print“错误号:”&err.Number&vbNewLine&vbNewLine&“说明:”&err.Description,vbCritical,“错误”
如果错误号=-2147467259,则
MsgBox“发生错误-检查要嵌入的文件或目标PPT是否与Excel文件位于同一文件夹中…”
如果结束
如果错误号=462,则
设置PP_File=PowerPointApp.Presentations.Add
转到rrr
如果结束
如果错误编号=16,则
MsgBox“检查要嵌入的Excel文件是否在同一文件夹中…”
终点
如果结束
端接头

我在Excel中遇到了类似的问题,在下一个代码中出现了错误。虽然我很少使用它(我更喜欢体验所有的错误并适当地处理它们),但它在某些有限的情况下是有用的。我找到了重新思考一些代码的方法,例如,在您的示例中,您展示了以下内容:

On Error Resume Next
'Is PowerPoint already opened?
Set PowerPointApp = GetObject(class:="PowerPoint.Application")
'Clear the error between errors
err.Clear
'If PowerPoint is not already open then open PowerPoint
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
我将把这篇文章重新编码如下:

bPPOpen = GetObject(class:="PowerPoint.Application")
If bPPOpen Then 
   Set PowerPointApp = GetObject(class:="PowerPoint.Application")
Else bPPOpen = False Then
   Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
Endif

使用此技术,除非您知道对象可用,否则您永远不必尝试设置对象。此外,由于您没有使用引发的错误,因此不必处理某些错误“清理”。

在Windows 10下的64位Office 2019中,我没有看到任何错误。可能您在一台机器上存在配置问题。Yaaa多台PC,这就是为什么请注意,就像您在“错误恢复下一步”中使用的
,它会隐藏所有错误消息,直到
End Sub
,这是一种非常糟糕的做法。在错误检查
err.Number=429
结束后,如果没有
,请转到0
(重新激活错误报告),切勿使用它。看见如果在错误恢复下一步时删除
,错误会发生在哪一行?同时使用
。选择
是一种非常糟糕的做法,您应该加以纠正:.•此外,您还需要使用大量的
GoTo
,这应该避免,因为它会把代码弄得一团糟
GoTo
只能在出现错误时与
结合使用…
。我检查过了。。它确实会触发-err.Number=429。。即使powerpoint已安装或打开没关系。。
bPPOpen = GetObject(class:="PowerPoint.Application")
If bPPOpen Then 
   Set PowerPointApp = GetObject(class:="PowerPoint.Application")
Else bPPOpen = False Then
   Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
Endif