Hi Hans,
I have created a menu in my excel program. I want to open this menu from my power point presentation using an activeX control "button". I have used this code but an error is coming.
Private Sub CommandButton1_Click()
Workbooks.Open "C:\Users\admc\Desktop\Tony\Menu.xlsm"
ActiveWorkbook.Sheets(1).Select
End Sub
From excel to excel the code is working nicely but from ppt to excel, error is coming.
Thanks,
Nasser.
Opening an excel sheet from PPT
-
- Administrator
- Posts: 77254
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Opening an excel sheet from PPT
"Workbooks" and "ActiveWorkbook" belong to Excel VBA, not to PowerPoint VBA. If you want to use Excel VBA in PowerPoint, you must use Automation and create an Excel application object:
Change the code as follows:
- Activate the Visual Basic Editor.
- Select Tools | References...
- Locate the Microsoft Excel n.0 Object Library in the list; n is a number that depends on the version you have (n=10 for Excel 2002, n=11 for Excel 2003, n=12 for Excel 2007 and n=14 for Excel 2010)
- Tick the check box for this library and click OK.
Change the code as follows:
Code: Select all
Private Sub CommandButton1_Click()
Dim xlApp As Excel.Application
Dim xlWbk As Excel.Workbook
Set xlApp = CreateObject("Excel.Application")
Set xlWbk = xlApp.Workbooks.Open("C:\Users\admc\Desktop\Tony\Menu.xlsm")
xlWbk.Sheets(1).Select
xlApp.Visible = True
End Sub
Regards,
Hans
Hans
-
- StarLounger
- Posts: 56
- Joined: 11 May 2010, 10:26
Re: Opening an excel sheet from PPT
Hi Hans,
From PPT, after clicking on the button, an error is coming:
Compile error:
User-defined type not defined
and "Dim xlApp As Excel.Application" declaration is highlighted.
Thanks,
Nasser.
From PPT, after clicking on the button, an error is coming:
Compile error:
User-defined type not defined
and "Dim xlApp As Excel.Application" declaration is highlighted.
Thanks,
Nasser.
-
- Administrator
- Posts: 77254
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Opening an excel sheet from PPT
Have you set a reference to the Microsoft Excel n.0 Object Library, as I described in my previous reply?
Regards,
Hans
Hans
-
- StarLounger
- Posts: 56
- Joined: 11 May 2010, 10:26
Re: Opening an excel sheet from PPT
Sorry i forgot that. Great it's working :)
Thank you Hans
Cheers,
Nasser.
Thank you Hans
Cheers,
Nasser.