从Excel VBA运行Powerpoint子 [英] Run Powerpoint sub from Excel VBA

查看:53
本文介绍了从Excel VBA运行Powerpoint子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Excel中的子目录运行PowerPoint子目录.原因是与从Excel的子目录运行相比,大多数PowerPoint动作从PowerPoint的子目录运行的速度更快,错误更少.

I need to run a PowerPoint sub from a sub in Excel. The reason is that most PowerPoint actions run far faster and with less errors when run from a sub in PowerPoint than when run from a sub in Excel.

我正在尝试使用 Application.Run(Macroname_As_String),其中我使用 PptApp 代替了 Application PptApp 加载为:

I am trying to use Application.Run(Macroname_As_String) where I use PptApp in place of Application and PptApp is loaded as:

Dim PptApp As PowerPoint.Application
Set PptApp = CreateObject("PowerPoint.Application")

我尝试将VBA脚本称为 Presentation1.pptm!UpdateOLELinks UpdateOLELinks .文件和VBA脚本/只是VBA脚本.

I tried referring to the VBA script as both Presentation1.pptm!UpdateOLELinks and UpdateOLELinks ie. file and VBA script / just VBA script.

我收到错误消息:

对象'_Application'的方法'运行'失败".

"Method 'Run' of object '_Application' failed".

我的VBA脚本 UpdateOLELinks 位于 Presentation1 Module1 中.

My VBA script UpdateOLELinks is located in Module1 of Presentation1.

有什么想法吗?

推荐答案

有两个问题(对于PowerPoint来说似乎是唯一的),必须提供参数,并且宏名称必须完全合格.

There are two issues (which seem unique to PowerPoint), parameters are required and the macro name must be fully qualified.

在对宏进行限定时,请勿像对Excel那样使用单引号.相反,即使文件名包含空格,也请使用以下命令:

When qualifying the macro, don't use single quotes as you would for Excel. Instead, just use the following, even if the filename has spaces:

PptApp.Run Ppt1.Name & "!Module1.UpdateOLELinks"

如果传递的参数与宏的参数不匹配,也会发生错误.即使没有使用该宏,也要确保该宏具有已定义的参数来接收(匹配类型).

The error will also arise if the parameters being passed don't match the parameters of the macro. Ensure the macro has a defined parameter to receive (of matching type), even if it doesn't use it.

这篇关于从Excel VBA运行Powerpoint子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆