zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Excel: 通过VBA代码打开ppt文件

Excel文件代码 通过 打开 ppt vba
2023-06-13 09:12:58 时间

文章背景:使用Excel的Userform时,有时想要打开指定路径的ppt文件。下面介绍两种打开ppt文件的方式。

方法1:Presentations.Open method

示例:

命令按钮打开文件中的代码如下:

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:Shell function

示例:

命令按钮打开文件(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)