1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
Private Sub ComboBox1_Change()
ActiveDocument.FormFields("Text1").Result = ComboBox1.Value
End Sub
Private Sub CommandButton1_Click()
Unload UserForm1
End Sub
Private Sub UserForm_Initialize()
On Error Resume Next
Dim xlApp As Object
Dim xlWb As Object
Dim xlSh As Object
Dim dlg As FileDialog
Dim stFile As String
Dim i As Integer
Set xlApp = CreateObject("excel.application")
Set xlWb = xlApp.workbooks.Open("P:\Utilisateur\Feuille\liste maires en seine maritime.xlsm")
Set xlSh = xlWb.sheets(1)
Debug.Print xlSh.usedrange.Rows.Count
For i = 1 To xlSh.usedrange.Rows.Count
Debug.Print i
Me.ComboBox1.AddItem (xlSh.Cells(i, 1))
Debug.Print xlSh.Cells(i, 1)
Next i
moi:
Set xlSh = Nothing
Set xlWb = Nothing
Set xlApp = Nothing
xlApp.Quit
End Sub |
Partager