Variable Non reconnue par ma Sub
Bonjour
J'ai un Userform dont le code est le suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| Private Sub CommandButton1_Click()
Dim FichierChoisi As String
FichierChoisi = Application.GetOpenFilename
Dim j As Integer
Dim con As ADODB.Connection
With con
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FichierChoisi & _
";Extended Properties=""Excel 12.0;HDR=YES;"""
.Open
End With
Call ImportDonnées
End Sub |
et j'ai ma sub nommée ImportDonnées contenue dans un module dont le code est le suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Sub ImportDonnées()
Dim wbContrepartie As Workbook
Dim n3 As Integer
Set wbContrepartie = Workbooks.Open(FichierChoisi)
Sheets(Feuil1).Select
n3 = Workbooks("TP8").Sheets.Count
Sheets(Feuil1).Copy After:=Workbooks("TP8.xlsm").Sheets(n3)
wbContrepartie.Close
Set wbContrepartie = Nothing
Workbooks("TP8").Sheets(Feuil1).Select
End Sub |
le problème c'est que ma macro s'arrête à ce niveau
Code:
Set wbContrepartie = Workbooks.Open(FichierChoisi)
en me disant que ma variable FichierChoisi n'est pas définie.
Je ne sais pas comment la déclarer dans ma sub. Merci de m'apporter votre aide.