[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Word VBA Self-Reference

Posted on 2009-03-30
4
Medium Priority
?
1,555 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 48

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 48

Assisted Solution

by:Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs) earned 640 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Suggested Courses
Course of the Month19 days, 16 hours left to enroll

873 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