+ Reply to Thread
Results 1 to 5 of 5

Adding a Control Caption

  1. #1
    Registered User
    Join Date
    08-22-2007
    Posts
    26

    Adding a Control Caption

    I am making a userform that will have a varied amount of checkboxes dependent on how many worksheets there are. I 've programmed it so that for each worksheet, userform.controls.add a checkbox. Now, my problem with this is that (at least in VBA6) .caption is not a property of a Control. So when I set the .caption of each checkbox, I get an automation error. Is there a way to set the caption on a Control that is created by VBA? Otherwise, I'll just create a bunch of checkboxes and just make them visible or not. I'd rather not do this, but I could.

    Nick.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Adding a Control Caption

    What code are you using? It should be perfectly possible to do that (though I'd probably use a listbox myself - you can style it with checkboxes too if you like).
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    08-22-2007
    Posts
    26

    Re: Adding a Control Caption

    Here is my current code. (Functionality is not complete, but you get the gist). I've put faces at the important lines


    Dim getBk As Workbook, getStr As String, setBk As Workbook, boxes(1 To 255) As Control, ws As Worksheet
    getStr = Application.GetOpenFilename
    Application.ScreenUpdating = False
    Set getBk = Workbooks.Open(getStr)
    For Each ws In getBk.Sheets
    sheetGetter.Height = sheetGetter.Height + 18
    Set boxes(ws.Index) = sheetGetter.Controls.Add("Forms.CheckBox.1", "box" + CStr(ws.Index), True)
    boxes(ws.Index).Top = 50 + (ws.Index - 1) * 18
    boxes(ws.Index).Caption = ws.Name
    Next
    getBk.Close (False)

    The "cool" face is where I define the control itself. The "mad" face shows what's not working. I'm going to look into the listbox and see if that makes more sense to my purposes. I have a feeling that I might run into a similar problem, though. Thanks.

    Nick.

  4. #4
    Registered User
    Join Date
    08-22-2007
    Posts
    26

    Re: Adding a Control Caption

    Nevermind. I'm doing the listBox. It makes much more sense. Thanks for the tip!

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Adding a Control Caption

    Redux,

    Please edit your post to add code tags.
    Entia non sunt multiplicanda sine necessitate

+ 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