Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Word VBA Self-Reference

Posted on 2009-03-30
4
1,465 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)
ID: 24026103
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
ID: 24027791
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
ID: 24027877
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
ID: 24034308
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.

809 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