Solved

Word VBA Self-Reference

Posted on 2009-03-30
4
1,443 Views
Last Modified: 2013-12-20
Hi,

I have a document with a number of Control Checkboxes.
Im trying to get a checkbox to refer to itself when clicked.
Say I want to obtain the name or the value of the checkbox whose status I just changed...

For example something like

Private Sub CheckBoxB_Change()
    MsgBox <THIS CHECKBOX>.Name
    MsgBox <THIS CHECKBOX>.Value
End Sub


I'm using Ms Word 2003...
0
Comment
Question by:Strobo
  • 2
  • 2
4 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
Comment Utility
You can access the current control using Me.ActiveControl.....

    Private Sub CheckBoxB_Change()
        MsgBox Me.ActiveControl.Name
        MsgBox Me.ActiveControl.Value
    End Sub

Wayne
0
 
LVL 2

Author Comment

by:Strobo
Comment Utility
Hi Wayne...

I tried that already. I get an error message "Method or data member not found".

I think that would work in Excel, but not in Word. Yeah, I keep running into simple ways to do things in excel and can only wonder why they dont work in Word. :-(

Any other ideas?
0
 
LVL 47

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 160 total points
Comment Utility
Sorry, I thought you were using a UserForm.

On the document there doesn't appear to be a way to get the active control. But why do you need it? If "CheckBoxB_Change" is called, obviously the controls name is "CheckBoxB". If you are after a method by which you can copy the same routine to numerous controls, consider using a separate routine....
Private Sub CheckBox1_Change()

     CheckBox_Change CheckBox1

End Sub
 

Private Sub CheckBox2_Change()

     CheckBox_Change CheckBox2

End Sub
 

Sub CheckBox_Change(ByRef cb As Object)

     MsgBox cb.Value

End Sub

Open in new window

0
 
LVL 2

Accepted Solution

by:
Strobo earned 0 total points
Comment Utility
Yes, thats how Im currently doing it... but, to be honest, I have about a million checkboxes and was hoping there would be an easier way then writing this out for each one.

Maybe I should just try switching to UserForm... although that gives me other issues.

Anyway... thanks..
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now