Bonjour,
Je decouvre VBnet et je cherche à transposer un petit programme que j'ai fais sous VBA6 sous excel.
Pouvez vous me dire si c'est possible et comment s'il vous plait merci.
VBnet semble plus adapté pour ce que je souhaite faire.
Voici la base du code que j'utilise :
VBnet semble ne pas aimer la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
46
47
48
49
50
51
52
53
54 Dim Cn As ADODB.Connection Dim Fichier As String Dim NomFeuille As String, texte_SQL As String Dim Rst As ADODB.Recordset Fichier = "C:\Base de données.xls" NomFeuille = "Data" Set Cn = New ADODB.Connection '--- Connexion --- With Cn .Provider = "Microsoft.Jet.OLEDB.4.0" .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _ & Fichier & ";Extended Properties=""Excel 12.0;HDR=YES;""" .Open End With '----------------- texte_SQL = "SELECT * FROM [" & NomFeuille & "$]" Set Rst = New ADODB.Recordset Set Rst = Cn.Execute(texte_SQL) i = 0 UserForm2.MSFlexGrid1.Clear UserForm2.MSFlexGrid1.Rows = 1 txtcol = "ID|" For nbcol = 0 To Rst.Fields.Count - 1 txtcol = txtcol & Rst.Fields(nbcol).Name & "|" Next nbcol txtcol = Left(txtcol, Len(txtcol) - 1) UserForm2.MSFlexGrid1.FormatString = txtcol i = 0 While Not Rst.EOF i = i + 1 MSFlexGrid1.Rows = i + 1 MSFlexGrid1.ColWidth(0) = 400 MSFlexGrid1.TextMatrix(i, 0) = i For Col = 1 To UserForm2.MSFlexGrid1.Cols - 1 MSFlexGrid1.ColWidth(Col) = 2000 MSFlexGrid1.TextMatrix(i, Col) = Rst.Fields(Rst.Fields(Col - 1).Name) Next Col Rst.MoveNext Wend '--- Fermeture connexion --- Cn.Close Set Cn = Nothing
Code : Sélectionner tout - Visualiser dans une fenêtre à part ADODB.Connection
Partager