Log in

View Full Version : [SOLVED:] Opening and closing an Excel document in Powerpoint



murathison
07-20-2016, 06:26 AM
Hi guys,

this my first post in this forum so please apologize any shortcomings..

I have a problem with opening an Excel document (same path as PowerPoint presentation) and closing it afterwards.

I always get the same message saying that an Object is required although I did initiate an object. (On the line Set xlWB.....)

Because I am quite new to VBA I would appreciate your help.

Please see my code below:


Sub mapa()

Dim ApXL As Object
Dim xlWB As Object
Dim xlWS As Object

Set ApXL = CreateObject("Excel.Application")
Set xlWB = ApXL.Workbooks.Open(FileName:=Presentation.Path & "\Feedback.xlsm")
ApXL.Visible = True

Set xlWS = xlWB.Worksheets("Feedback")
xlWS.Activate

.......
.......
.......

xlWB.Quit
xlWS.Quit
ApXL.Quit
Set xlWS = Nothing
Set x1WB = Nothing
Set ApXL = Nothing




Thank you very much in advance.


Saludos:yes

John Wilson
07-20-2016, 07:14 AM
xlWS.Quit -- You cannot Quit a worksheet remove that line

xlWB.Quit -- You cannot Quit a Workbook but you can Close it. xlWB.Close

murathison
07-20-2016, 11:14 AM
Hi John Wilson,


thanks for the reply.

The thing is, I already get the error message in the line starting with "Set XLwb...". So the first step I need to take is to open the Workbook before thinking about how to close it ��

Do you have any idea on how to solve that problem?

Thanks in advance,

Saludos:hi:

murathison
07-21-2016, 12:17 AM
Hi guys,

thought I would let you know that I solved the problem:



Dim ApXL As Object


Set ApXL = CreateObject("Excel.Application")
ApXL.Workbooks.Open "C:\Users\f131ho0\Documents\16-07-20 Mapa con precios\Feedback.xlsm"
ApXL.Visible = False

ApXL.Run "Durchschnitt"

.....
.....
.....

ApXL.Visible = True
ApXL.Quit
Set ApXL = Nothing



The only thing that is missing now is giving a relative instead of an absolute path, I am not sure how to do this and have already tried some options but we'll see. If you could help me I would appreciate it.

Thanks guys!

Saludos:yes

John Wilson
07-21-2016, 12:53 AM
This Line


Set xlWB = ApXL.Workbooks.Open(FileName:=Presentation.Path & "\Feedback.xlsm") Should be :

Should be

Set xlWB = ApXL.Workbooks.Open(FileName:=ActivePresentation.Path & "\Feedback.xlsm")

murathison
07-21-2016, 01:20 AM
Yes, perfect! Works now.

Thank you!

Saludos:hi: