+ Reply to Thread
Results 1 to 4 of 4

Dynamically link to control via module

Hybrid View

  1. #1
    Registered User
    Join Date
    03-03-2008
    Posts
    2

    Dynamically link to control via module

    Hello,

    I am trying to code to a combobox on a worksheet (Excel 2003) from a module using variables.

    The following code gets me part of the way:

    Dim wbHold As Workbook
    Set wbHold = ThisWorkbook
    
    
    wbHold.Worksheets("Worksheet1").combobox1.AddItem "test"
    However I need to replace the name "combobox1" with a variable.




    Thanks
    Last edited by VBA Noob; 03-03-2008 at 11:59 AM.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning DelScorcho

    Quote Originally Posted by DelScorcho
    However I need to replace the name "combobox1" with a variable.
    How about :
    a = "ComboBox1"
    wbHold.Worksheets("Worksheet1").Controls(a).AddItem "test"
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    03-03-2008
    Posts
    2
    Quote Originally Posted by dominicb
    Good morning DelScorcho


    How about :
    a = "ComboBox1"
    wbHold.Worksheets("Worksheet1").Controls(a).AddItem "test"
    HTH

    DominicB
    Thanks, but I have tried that and I get the error: "Object doesn't support this property or method"

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi DelScorcho

    Quote Originally Posted by DelScorcho
    Thanks, but I have tried that and I get the error: "Object doesn't support this property or method"
    Yes. Course you did. That's 'cos I gave you the wrong code - I didn't read your post properly and thought you were using a userform. Fortunately, I know the right answer . Try this :
    a = "ComboBox1"
    Sheets("Worksheet1").OLEObjects(a).Object.AddItem "test"
    HTH

    DominicB

+ 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