文章背景:使用Excel的Userform时,有时想要打开指定路径的ppt文件。下面介绍两种打开ppt文件的方式。
示例:
命令按钮打开文件
中的代码如下:
Option Explicit
Private Sub CommandButton1_Click()
Dim wo
Set wo = CreateObject("Powerpoint.Application")
wo.Presentations.Open Filename:=TextBox1.Text, ReadOnly:=msoTrue
End Sub
运行效果:http://mpvideo.qpic.cn/0b78luaasaaaxuapgk4glfpvaxodbfoqacia.f10002.mp4?dis_k=5434748d7fe0413d0ca0651e3c283c02&dis_t=1663654740&vid=wxv_1561779249685004292&format_id=10002&support_redirect=0&mmversion=false
示例:
命令按钮打开文件(2)
中的代码如下:
Option Explicit
Private Sub CommandButton1_Click()
Dim filepath As String
filepath = TextBox1.Text
Shell "POWERPNT.EXE " & filepath, vbNormalFocus
End Sub
运行效果:http://mpvideo.qpic.cn/0b78piaasaaanmapfxegizpva6wdbf5aacia.f10002.mp4?dis_k=eee726bec4c72924e1f8c195b14f7860&dis_t=1663654740&vid=wxv_1561780077925826560&format_id=10002&support_redirect=0&mmversion=false
参考资料:
[1] excel中如何通过vba打开ppt文件(http://club.excelhome.net/thread-550712-1-1.html)
[2] Presentations.Open method (PowerPoint)(https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentations.open)
[3] VB运行文件(Shell)为什么只显示在任务栏里面而不直接弹出(http://www.mh456.com/s/fxztffwxkyry/fxztffwxkyrytjzj.html)
[4] Shell function(https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/shell-function)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有