+ Reply to Thread
Results 1 to 4 of 4

referencing form control labels in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    09-19-2008
    Location
    Gloucester, MA
    MS-Off Ver
    Excel 2016
    Posts
    62

    referencing form control labels in VBA

    I need to hide the labels on a sheet if a certain cell has a specific value. The labels are not activeX labels, but are the form control labels. I know how to loop through activeX controls. See code below. But how do I code this for the form control label?

       For Each OleObj In ActiveSheet.OLEObjects
          If OleObj.progID = "Forms.Label.1" Then
             OleObj.Object.Visible = False
          End If
      Next OleObj

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: referencing form control labels in VBA

    For each ctrl in Userforms!Form1.controls
    if ctrl.label = "test text" Then 'modify this line
    ctrl.visible = False
    End if
    Next ctrl
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    09-19-2008
    Location
    Gloucester, MA
    MS-Off Ver
    Excel 2016
    Posts
    62

    Re: referencing form control labels in VBA

    I'm a bit confused how to use Userforms!Form1.controls in code. The labels are on the worksheet not a form, so this didn't work in my code. I got a 'Type Mismatch' error.

    Thanks.

  4. #4
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: referencing form control labels in VBA

    Please upload your workbook and I'll take a look at it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1