我需要在关闭电源点应用程序时打开一个excel工作表

时间:2015-02-23 10:05:14

标签: excel vba excel-vba powerpoint

如果某人要更新电源点,他们还需要更新excel表如何实现这一点? 我相信它可以通过宏来完成,但我对它并不好。请帮助我...

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim strFile As String
Dim WB As Workbook
If ThisWorkbook.Saved = False Then
Dim DirFile As String
DirFile = "C:\Users\tg2412\Documents\1.xlsx"
If Len(Dir(DirFile)) = 0 Then
  MsgBox "File does not exist"
Else
 Set WB = Workbooks.Open(DirFile)
 End If    
   End If
End Sub

提前致谢...:)

1 个答案:

答案 0 :(得分:0)

你需要两件事:

事件处理:

您的powerpoint需要处理演示关闭事件,除非您打算以编程方式关闭它。如果是,请跳至下一个标题。 Powerpoint事件并不像Excel那样简单。这是一个开始的地方:

http://www.pptfaq.com/FAQ00004_Make_your_VBA_code_in_PowerPoint_respond_to_events.htm

Excel应用程序对象:

使用Excel应用程序对象从Powerpoint启动Excel:

Dim Excel As Object
Dim Workbook As Object
Set Excel = CreateObject("Excel.Application")
Excel.Visible = True 'Set this to false if you want Excel to work in the background
'Add more code to verify the path with dir()
Set Workbook = Excel.Workbooks.Open("YourPathHere", True, False)