Open Excel file in VBA from Powerpoint

Have you added a reference to the Excel Object Model? That would save you having to use the late bound objects (and you get the benefit of having the Intellisense help when you are coding).

You need to go to Tools -> References and check the "Microsoft Excel v.x Object Library" (I think that number changes depending on the version of office you are using.

Your code should work if you do that, you should also remove the

CreateObject("Excel.Application") 

line and replace it with

Set xlApp = new Excel.Application

And move the

Set xlApp = nothing

line to the end of your subroutine.

The rest of your code looks fine to me.


Late binding code would be this

Private Sub test()
Dim xlApp As Object
Dim xlWorkBook As Object

Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = True
Set xlWorkbook = xlApp.Workbooks.Open("C:\lol\Book1.xlsx", True, False)
xlWorkbook.sheets(1).Range("A8").Value = "Hello"

Set xlApp = Nothing
Set xlWorkbook = Nothing


End Sub

It's better to use early binding though.

Tags:

Vba

Powerpoint