By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

Give Values to Combo Box programmatically

P: 1
Hello friends,
i have a situation where i have to take the values of combo box from the program. how can i do that.
Let me explain in detail...
i have a form which imports value from a excel sheet which can contain n number of worksheets in it. So when i select a particular excel i should open a combo box which get the names of all the worksheet it contains. Can any body help me out..... Thanks in advance
May 18 '07 #1
Share this Question
Share on Google+
1 Reply


maxamis4
Expert 100+
P: 295
Man thats a tough request. So i need to recap for everyone:

1 Basically you just want to set your combo box equal to all the names of the excel spreadsheets inside your workbook right?

Now as far as filling out the combo box, I would recommend an array. Something like this this also includes the excel piece you requested.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function get_spreadsheetName()
  3.  
  4. Public objapp As Excel.Application
  5. Public objbook As Excel.Workbook
  6. Public objsheet As Excel.Worksheet
  7. dim myarray as string
  8. dim i, y as integer 
  9. i = 0
  10.  
  11. 'Delcare file path where workbook is stored
  12. Filepath = FileLocation
  13.  
  14. Set objbook = Workbooks.Add(Template:=Filepath)  'Your excel spreadsheet file goes here
  15. Set objapp = objbook.Parent
  16.  
  17. Y = objapp.ActiveWorkbook.Worksheets.Count
  18.  
  19. For i = 1 To Y
  20.           Set oSheet = objapp.ActiveWorkbook.Worksheets(i)
  21.           sheetName = oSheet.name
  22.           Redim myarray(i)
  23.  
  24.                            myarray(i) = SheetName
  25.  
  26. Next i
  27.  
  28. cmbList.RowSource = "" 'clears the list inside your combo box
  29.  
  30.   For i = 1 To Y
  31.         strRowSource = strRowSource & MyArray(i) & ";" 
  32.     Next i
  33.  
  34. cmbList.RowSource = strRowSource
  35.  
  36. end function     
  37.  
Note i have not tested this but I think this is what you want. You need to study up on the Excel object library to understand how this works.

Hello friends,
i have a situation where i have to take the values of combo box from the program. how can i do that.
Let me explain in detail...
i have a form which imports value from a excel sheet which can contain n number of worksheets in it. So when i select a particular excel i should open a combo box which get the names of all the worksheet it contains. Can any body help me out..... Thanks in advance
May 18 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.