Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 06-23-2020, 01:17 AM
ydmq ydmq is offline How to add an event on a shape in document? Windows 10 How to add an event on a shape in document? Office 2013
Banned
How to add an event on a shape in document?
 
Join Date: Jun 2020
Posts: 6
ydmq is on a distinguished road
Question

Quote:
Originally Posted by gmaxey View Post
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 ~
Reply With Quote
 

Tags
shape



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add an event on a shape in document? Unable to get cursor past inserted shape in Word document slknova Word 6 11-09-2021 09:02 AM
I don't understand event handling for the DoubleClick event Larry_1 Excel Programming 5 12-28-2017 08:23 AM
How to change size / shape of a shape in a stencil tomgoodell Visio 1 06-30-2016 04:40 AM
Shape hyperlink doesn't work with protected form document Cosmo Word 0 12-10-2012 01:42 PM
Connect Outlook "Event" to Office Document Yick Office 1 09-23-2011 04:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:03 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft