Bonjour le forum,
j'ai une question sur le chargement d'une liste...
En français : Si un élément de ma liste a déja été inséré dans ma colonne, j'aimerai que celui-ci n'apparaissent plus dans la liste!
Mon bout de code :
J'ai un problème de rafraichissement, c'est à dire que la MAJ de ma liste se fait uniquement quand je quitte mon UserForm et que je l'ouvre de nouveau...
Avez-vous une idée ?
j'ai une question sur le chargement d'une liste...
En français : Si un élément de ma liste a déja été inséré dans ma colonne, j'aimerai que celui-ci n'apparaissent plus dans la liste!
Mon bout de code :
Code:
Private Sub B_AddXml_Click()
Dim Result As Object 'Result if we found the same name in the list
Dim lgDerLig As Long 'Catch the last Xml name
' Catch the last line in the A column
lgDerLig = Range("A" & Cells.Rows.Count).End(xlUp).Row + 1
' Verify that the equipment do not already exist
Set Result = Range("A6:A" & lgDerLig).Find(What:=Me.Cbx_AddXml, LookIn:=xlValues, lookat:=xlWhole)
If Not Result Is Nothing Then
MsgBox "This Xml file already exists !", , "WARNING..."
Exit Sub
End If
'Transfert the XmlFile
If Me.Cbx_AddXml = "" Then concat = concat & Me.Cbx_AddXml.ControlTipText & vbCrLf
' Message box
If concat <> "" Then
MsgBox "You have no Xml files selected !", , "WARNING..."
Exit Sub
Else
'Select the good location
Range("A" & lgDerLig).Select
strChaine = Cbx_AddXml.Value
'Cannot contain the extentions xls or xml
intCar = InStr(InStr(1, strChaine, Left(".extension", 10)) + 3, strChaine, ".")
If intCar > 0 Then
strChaine = Mid(strChaine, 1, intCar - 1)
End If
ActiveCell.Value = strChaine
Sheet1.Cells(lgDerLig, 1).Interior.Color = RGB(255, 0, 0)
Application.Calculate
'Initialize
Cbx_AddXml.ListIndex = -1
End If
End Sub
Private Sub Cbx_AddXml_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr("[abcdefghijklmnopqrstuvwxyz][ABCDEFGHIJKLMNOPQRSTUVWXYZ][0123456789][_-]", Chr(KeyAscii)) = 0 Then
KeyAscii = 0
Beep
End If
End Sub
Private Sub UserForm_Initialize()
Dim EquiType As String 'Equipment type
Dim XmlFiles As String 'List of the Xml files per equipment
Dim XmlFileWE As String 'Xml file without extension
Dim Result As Object 'Result if we found the same name in the list
Dim lgDerLig As Long 'Catch the last Xml name
'Folder test
x = Split(ActiveWorkbook.Path, "\")
nRep = x(UBound(x))
If (nRep = "Excel") Then
EquiType = Range("B2").Value
'PathEquiType = Mid(ActiveWorkbook.Path, 1, InStr(1, ActiveWorkbook.Path, Left("\Excel", 7)) - 1) & "\Xml\"
XmlFiles = Dir("..\Xml\" & EquiType & "\*.xml")
' Catch the last line in the A column
lgDerLig = Range("A" & Cells.Rows.Count).End(xlUp).Row + 1
'Set Result = Range("A6:A" & lgDerLig).Find(What:=XmlFileWE, LookIn:=xlValues, lookat:=xlWhole)
Do While XmlFiles <> ""
XmlFileWE = Mid(XmlFiles, 1, InStr(1, XmlFiles, Left(".xml", 4)) - 1)
' Verify that the equipment do not already exist
Set Result = Range("A6:A" & lgDerLig).Find(What:=XmlFileWE, LookIn:=xlValues, lookat:=xlWhole)
If Result Is Nothing Then Cbx_AddXml.AddItem XmlFileWE
XmlFiles = Dir
Loop
End If
End Sub
J'ai un problème de rafraichissement, c'est à dire que la MAJ de ma liste se fait uniquement quand je quitte mon UserForm et que je l'ouvre de nouveau...
Avez-vous une idée ?