简体   繁体   中英

I need to open an excel worksheet while closing an power point application

If some one is going to update the power point they also need to update the excel sheet how to make this happen? I am sure it can be done through macro but i am not good with it.kindly help me out...

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

Thanks in advance...:)

You need two things:

Event handling:

Your powerpoint needs to handle the presentation close event unless you intend to close it programatically. If so, skip to the next heading. Powerpoint events are not as straightforward as Excel's. Here's a place to start with:

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

Excel Application object:

Use Excel application object to launch Excel from Powerpoint:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM