Open Excel file in VBA from Powerpoint

◇◆丶佛笑我妖孽 提交于 2019-12-04 04:37:08

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!