Créer une liste (via un second fichier)

K

Kato

Guest
Bonjour,

Je cherche un moyen de créer une liste dans une cellule. La liste doit aller chercher les informations dans un autre fichier excel.

comment faire.. ???

(je n'ai rien trouvé sur internet... )

c'est hyper urgent... et je suis bloqué depuis 10 jours :(

kato.news@club-internet.fr
 
B

bebere

Guest
bonsoir Kato

je me sers du code qui suit,si problèmes tu nous reviens

Private Sub UserForm_Initialize()
' fill ListBox1 with data from a closed workbook
' can also be used from other applications to read data from an open workbook
Dim tArray As Variant
tArray = ReadDataFromWorkbook('D:\\FichierPartage2003\\entreefacture2003.xls', 'liste81')
FillListBox UserForm1.ListBox1, tArray
Erase tArray
End Sub

Private Sub FillListBox(lb As MSForms.ListBox, RecordSetArray As Variant)
' fills lb with data from RecordSetArray
Dim r As Long, C As Long
With lb
.Clear
For r = LBound(RecordSetArray, 2) To UBound(RecordSetArray, 2)
.AddItem
For C = LBound(RecordSetArray, 1) To UBound(RecordSetArray, 1)
.List(r, C) = RecordSetArray(C, r)
Next C
Next r
.ListIndex = -1 ' no item selected
End With
End Sub

Private Function ReadDataFromWorkbook(SourceFile As String, SourceRange As String) As Variant
' requires a reference to the Microsoft ActiveX Data Objects library (menu Tools, References in the VBE)
' if SourceRange is a range reference:
' this function can only return data from the first worksheet in SourceFile
' if SourceRange is a defined name reference:
' this function can return data from any worksheet in SourceFile
' SourceRange must include the range headers
' examples:
' varRecordSetData = ReadDataFromWorkbook('C:\\FolderName\\SourceWbName.xls', 'A1:A21')
' varRecordSetData = ReadDataFromWorkbook('C:\\FolderName\\SourceWbName.xls', 'A1:B21')
' varRecordSetData = ReadDataFromWorkbook('C:\\FolderName\\SourceWbName.xls', 'DefinedRangeName')
Dim dbConnection As ADODB.Connection, rs As ADODB.Recordset
Dim dbConnectionString As String
dbConnectionString = 'DRIVER={Microsoft Excel Driver (*.xls)};ReadOnly=1;DBQ=' & SourceFile
Set dbConnection = New ADODB.Connection
On Error GoTo InvalidInput
dbConnection.Open dbConnectionString ' open the database connection
Set rs = dbConnection.Execute('[' & SourceRange & ']')
On Error GoTo 0
ReadDataFromWorkbook = rs.GetRows ' returns a two dim array with all records in rs
dbConnection.Close ' close the database connection
'rs.Close
Set rs = Nothing
Set dbConnection = Nothing
On Error GoTo 0
Exit Function
InvalidInput:
MsgBox 'The source file or source range is invalid!', vbExclamation, 'Get data from closed workbook'
Set rs = Nothing
Set dbConnection = Nothing
End Function

à bientôt


:)
 
B

bebere

Guest
bonjour Kato
une tentative d'explication en pièce jointe
à bientôt [file name=EssaiListbox.zip size=15954]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/EssaiListbox.zip[/file]
 

Pièces jointes

  • EssaiListbox.zip
    15.6 KB · Affichages: 21
  • EssaiListbox.zip
    15.6 KB · Affichages: 20
  • EssaiListbox.zip
    15.6 KB · Affichages: 23

Discussions similaires

Statistiques des forums

Discussions
312 429
Messages
2 088 351
Membres
103 824
dernier inscrit
frederic.marien@proximus.