borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Save data from userform input)Next Topic (excel vb message box) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Combobox
Poster Message
mayanair
Level: Guest


icon Combobox

How to fill a list of values from an excel  worksheet into a combobox in a different excel worksheet?? Thanx

03-06-2003 at 07:05 AM
| Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: Combobox

This'll do what you need...


(Runs a Microsoft Excel 4.0 macro function and then returns the result of the function by filling a Combo Box.)


Sub GoDoIt()

Dim Path As String
Dim fname As String
Dim sht As String
Dim ref As String
Dim y As Integer 'Rows Variable

Sheet1.ComboBox1.Clear

path = "C:"
fname = "FileName.xls"
sht = "Sheet1"
    
For y = 1 To 10   'Or however many rows of list items you have

    ref = "A" & y
    Sheet1.ComboBox1.AddItem GetXLSVal(path, file, sht, ref)

Next y

End Sub



Private Function GetXLSVal(path As String, file As String, sheet As String, ref As String)

Dim arg As String

'Make sure the file exists
'No Other Error Checking in Here either...
    
'   Create the argument
    arg = "'" & path & "[" & file & "]" & sheet & "'!" & Range(ref).Range("A1").Address(, , xlR1C1)
'   Execute an XLM macro
    GetXLSVal = ExecuteExcel4Macro(arg)
End Function





[editted for typo]

[Edited by ~Bean~ on 03-06-2003 at 08:40 AM GMT]

____________________________
Eggheads unite! You have nothing to lose but your yolks.

03-06-2003 at 01:37 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Combobox
Previous Topic (Save data from userform input)Next Topic (excel vb message box) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder