Quote:
Originally Posted by gmaxey
You could use the Selection Change event. Insert a new Class module and name it clsMonitor. Insert this code:
Code:
Option Explicit
Private WithEvents mWordApp As Word.Application
Private oShp As Shape
Private Sub Class_Initialize()
Set mWordApp = Word.Application
End Sub
Private Sub mWordApp_WindowSelectionChange(ByVal oSel As Selection)
If Selection.ShapeRange.Count = 1 Then
If oShp Is Nothing Then
Set oShp = Selection.ShapeRange(1)
Select Case oShp.TextFrame.TextRange.Text
Case "Test" & Chr(13): MsgBox oShp.TextFrame.TextRange.Text
Case "Good" & Chr(13): MsgBox oShp.TextFrame.TextRange.Text
'Etc.
End Select
Else
If Selection.ShapeRange.TextFrame.TextRange <> oShp.TextFrame.TextRange Then
Set oShp = Selection.ShapeRange(1)
Select Case oShp.TextFrame.TextRange.Text
Case "Test" & Chr(13): MsgBox oShp.TextFrame.TextRange.Text
Case "Good" & Chr(13): MsgBox oShp.TextFrame.TextRange.Text
'Etc.
End Select
End If
End If
Else
Set oShp = Nothing
End If
End Sub
Insert a new standard module and insert this code:
Code:
Option Explicit
Private oCls As clsMonitor
Sub AutoOpen()
Set oCls = New clsMonitor
End Sub
Run AutoOpen and click in the Test or Good shapes. Adjust code to suit your needs.
|
Thank you for your reply~
I try it , but the result is wired.
I recorded the whole process as below:
myshape.mp4 - Google Drive
I am new about VBA,so I don't understand why it is like this.
In that video,it happends that some shapes is invisible.
Only the last one is visible.
Then,when I click the area where the shapes should be,two shapes appear(why ?) .
Thank you ~