一、打開word文件代碼:
Set wo = CreateObject("Word.Application") wo.Documents.Open ThisWorkbook.Path & "\流程.doc" wo.Visible = True
|
二、打開ppt文件代碼:
方法1:
Set wo = CreateObject("Powerpoint.Application") wo.Visible = True wo.Presentations.Open ThisWorkbook.Path & filename
|
方法2:
Sub dd() Dim filepath$, filename$ filepath = Chr(34) & ThisWorkbook.Path & filename & Chr(34) Shell "POWERPNT.EXE " & filepath End Sub
|
附:雙擊打開PPS文件,在演示完后退出PPS時并沒有PowerPoint主窗口保留,但在Excel中使用VBA打開的PPS文件,在演示完P(guān)PS退出后,PowerPoint主窗口仍然打開。
這里使用一個循環(huán)判斷演示窗口是否存在,加上錯誤捕捉程序來處理上面這個問題。
|
Private Sub CommandButton1_Click() Dim wo As Object Dim app As Object ' 創(chuàng)建PowerPoint應(yīng)用實(shí)例 Set app = CreateObject("Powerpoint.Application") ' 使PowerPoint可見 app.Visible = True ' 打開PPS文件 Set wo = app.Presentations.Open(ThisWorkbook.Path & "\a.pps") ' 當(dāng)PPS演示結(jié)束時,wo對象的SlideShowWindow不存在,捕捉到錯誤 On Error GoTo errHandle ' PPS演示時全屏 Do While wo.SlideShowWindow.isFullScreen DoEvents Loop errHandle: ' 退出PowerPoint app.Quit Set app = Nothing Set wo = Nothing End Sub
|
|