Home » excel » selection – Powerpoint VBA: is it possible to enable user to select range in Excel using a mouse/keyboard?

selection – Powerpoint VBA: is it possible to enable user to select range in Excel using a mouse/keyboard?

Posted by: admin May 14, 2020 Leave a comment

Questions:

In excel, you can have a user dynamically select a range of cells by selecting it with his/her mouse or keyboard (e.g., picture below, or simply when you’re typing up a formula on ENTER mode and proceed to select a range of cells):

enter image description here
Does anyone know if such a functionality is callable from a Powerpoint macro/add-in? Essentially, I would like to have a piece of code in Powerpoint that generates a similar dialogue that allows a user to directly select a range of cells in an excel spreadsheet, and have the PPT macro record what that range is.

Thank you!

How to&Answers:

Here is an example you using GetObject

Note: The Application.InputBox opens modally. You cannot use it across workbooks.

Option Explicit

Sub GetAddressFromExcel()
    Dim oXLApp As Object
    Dim Ret As Object

    '~~> Establish an EXCEL application object
    Set oXLApp = GetObject(, "Excel.Application")

    '~~> Show Excel
    oXLApp.Visible = True

    If oXLApp.Workbooks.Count = 0 Then
        oXLApp.Workbooks.Add
    End If

    On Error Resume Next
    Set Ret = oXLApp.InputBox("Please select Excel Range", Type:=8)
    On Error GoTo 0

    If Not Ret Is Nothing Then MsgBox Ret.Address

    '~~> CLEANUP
    oXLApp.Quit
    Set oXLApp = Nothing
End Sub