PDA

View Full Version : [SOLVED:] open a specific excel worksheet from powerpoint



bg66
02-18-2018, 11:37 AM
Hi,
I want open a specific excel worksheet from powerpoint.
I try:

Sub ApriExcel()
Dim xlApp As Object
Dim xlWorkBook As Object
Dim ExcelValue As Double
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkBook = xlApp.Workbooks.Open("C:\Users\Microsoft\Desktop\Formazione light\Formazione\Start formazione\Slides Ended\AvvioCorso.xlsm", True, False)
xlWorkBook.Worksheets("Start").Range("B2").Value 'give me a debug Error
End Sub


But debug does not like it :banghead:. Where am I wrong?

Thanks in advance
bg66

John Wilson
02-18-2018, 12:36 PM
It should not give a debug error. If there are problems with the path you may get a runtime error. Have you a screen shot of the error. Is Option Explicit ON?

I doubt whether ExcelValue is a Double but it should work.

Are you intentionally setting UpdateLinks to True ?

bg66
02-18-2018, 12:55 PM
Hello John,


It should not give a debug error. If there are problems with the path you may get a runtime error. Have you a screen shot of the error. Is Option Explicit ON?

https://i.imgur.com/2tZM6Iz.jpg


https://i.imgur.com/LwvNQfq.jpg



I doubt whether ExcelValue is a Double but it should work.

Are you intentionally setting UpdateLinks to True ?

No, sorry.I tried, badly, to change your macro posted in another thread.

John Wilson
02-18-2018, 02:31 PM
Don't know then. If you have been playing with code that opens Excel it might be worth checking you don't have an invisible copy open.

CTRL+SHIFT+ESC to open Task Manager. Choose processes and look for EXCEL.exe running in the background. If it's there are you don't have Excel open normally then End the process and try again.

bg66
02-18-2018, 03:28 PM
But is this script string,anyway,correct?

xlWorkBook.Worksheets("Start").Range("B2").Value

In Excel VBA the correct phrase is: ".Range("B2").Select".

Thanks for your answer.

John Wilson
02-19-2018, 12:28 AM
Depends what you are trying to do - as written you are correct it is incorrect

If you want to read the value in the cell

Excelvalue=xlWorkBook.Worksheets("Start").Range("B2").Value

is correct

If you want to select that cell then as you say ...