Determine active cell in a table using VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need to determine what cell the cursor is in or what cell the user
selected using a popup menu or something. I've been able to get the current
slide, but I need to get more granular than that. Is there a command in VBA
to get that information as the user is in design mode?

Thanks much!
Rob
 
I need to determine what cell the cursor is in or what cell the user
selected using a popup menu or something. I've been able to get the current
slide, but I need to get more granular than that. Is there a command in VBA
to get that information as the user is in design mode?

If it's a PPT table, you can iterate through the .Cells collection and test
each cell's .Selected property

With .Table

For x = 1 to .Rows.Count
For y = 1 to .Columns.Count
If .Cell(x,y).Selected Then
MsgBox "BINGO"
 
So that seems to work if the cell is actually selected. Is there any way to
tell if the cursor is just sitting in the cell, not necessarily selected?

Also, is there a WithEvents statement that I can use to capture a user
clicking or moving from cell to cell in a table?

Thanks!
Rob
 
So that seems to work if the cell is actually selected. Is there any way to
tell if the cursor is just sitting in the cell, not necessarily selected?

Good question. See below for your other question.
As to the first:

Sub TableTest()

Dim x As Long
Dim y As Long
Dim oSh As Shape
Dim oRng As TextRange

If ActiveWindow.Selection.Type = ppSelectionText Then
' The parent of the current text select is the shape's TextRange
' The parent of the TextRange is the shape itself
' We'll use that to get the name of the shape
' and compare that to the name of each cell in the table to see if we have a
match
Set oRng = ActiveWindow.Selection.TextRange
Set oSh = ActiveWindow.Selection.ShapeRange(1)

With oSh.Table
For x = 1 To .Rows.Count
For y = 1 To .Columns.Count
If .Cell(x, y).Shape.Name = oRng.Parent.Parent.Name Then
MsgBox "BINGO"
Debug.Print .Cell(x, y).Shape.Name
Debug.Print "Cell " & CStr(x) & ":" & CStr(y)
End If
Next
Next
End With

Else

Set oSh = ActiveWindow.Selection.ShapeRange(1)

With oSh.Table
For x = 1 To .Rows.Count
For y = 1 To .Columns.Count
If .Cell(x, y).Selected Then
MsgBox "BINGO"
End If
Next
Next
End With

End If


End Sub

Also, is there a WithEvents statement that I can use to capture a user
clicking or moving from cell to cell in a table?

Make PPT respond to events
http://www.pptfaq.com/FAQ00004.htm

Changing cells in a PowerPoint table will trigger the selection change event.
If the table came from Word or Excel, then no.
 
Back
Top