Bonjour, voilà je suis débutant vb excel, pour mes test j'enregistre mes macros et regarde la syntaxe, j'ai un probléme de variable, je vous envoie le code:
Private Sub CommandButton1_Click()
Dim lenom As Variant
lenom = Sheets("PAGE").Range("f1")
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=MEDIANE;UID=sa;;APP=Microsoft Office 2003;WSID=TSE5;DATABASE=MEDIANE" _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT BIDE.IDNOM " & Chr(13) & "" & Chr(10) & "FROM MEDIANE.dbo.BIDE BIDE" & Chr(13) & "" & Chr(10) & "WHERE (BIDE.IDNOM='lenom')" _
)
.Name = "Lancer la requête à partir de MEDIANE"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
Dans ma requéte je voudrais utiliser ma variable lenom, mais ça ne marche pas, je pense ne pas utiliser la bonne syntaxe.
Merci de votre aide
Gil