Solved

Word VBA Self-Reference

Posted on 2009-03-30
4
1,484 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
[X]
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
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
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 walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

738 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