Bonjour,

Dans mon projet je dois agencer des données remontées automatiquement dans un fichier Excel. Le code que je vais vous montrer vient du cours sur le VB.NET de M. Lasserre (Qui est super soit dit en passant), il a pour but de me familiariser avec le pilotage de Excel. Je l'ai modifié car le compilateur m'indiquait des erreurs. Le problème, c'est qu'il m'en reste "UNE" que je n'arrive pas à débugger.
Voilà le
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Option Explicit On
'Option Strict On
 
Imports System
Imports System.Windows.Forms
Imports System.Windows.Forms.Button
Imports System.Windows.Forms.TextBox
Imports System.Drawing.Bitmap
Imports Microsoft.Office.Interop.Excel
 
Module Program
Friend WithEvents cmdTrace As New System.Windows.Forms.Button
Friend WithEvents txtMini As New System.Windows.Forms.TextBox 
Friend WithEvents txtMaxi As New System.Windows.Forms.TextBox 
Dim Excel As New Microsoft.Office.Interop.Excel.Application
Dim txtFormule as New Microsoft.Office.Interop.Excel.Application
	Sub Main()		
		Console.WriteLine("Hello World!")
 
		' TODO: Implement Functionality Here
 
		Console.Write("Press any key to continue . . . ")
		Console.ReadKey(True)
	End Sub
	Private Sub cmdTrace_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdTrace.Click
		'Appel d'Excel et attribution des variables
		Dim AppExcel As New Microsoft.Office.Interop.Excel.Application
		Dim Classeur As Microsoft.Office.Interop.Excel.Workbook = AppExcel.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet)
		Dim Feuille As Microsoft.Office.Interop.Excel.Worksheet = Classeur.ActiveSheet
		'Nom des séries
		Feuille.Cells(1, 1).value = "X"
		Feuille.Cells(1, 2).value = Me.txtFormule.Text
		Feuille.Cells(2, 1).value = CDbl (txtMini.Text)
		'Création d'un tableau de 100 valeurs allant de min à max par pas fixe
		Feuille.Cells(2, 1).resize(101).DataSeries(Excel.XlRowCol.xlColums, Excel.XlDataSeriesType.xlDataSeriesLinear, ,(CDbl(txtMaxi.Text)-CDbl(txtMini.Text))/100)
		Feuille.Cells(2, 2).resize(101).formulalocal = Replace("=" & txtFormule.Text, "X", "LC(-1)",1,-1, CompareMethod.Text)
		Dim Maplage As Microsoft.Office.Interop.Excel.Range
		'Recherche les cellules en erreur
		MaPlage = Feuille.Cells(1, 2).rezise(102).SpecialCells(Excel.XlCellType.xlCellTypeFormulas,Excel.XlSpecialCellsValue.xlerrors)
		If Not MaPlage Is Nothing Then
			'Il y a des erreurs
			If MaPlage.Count = 101 Then
				MessageBox.Show("Erreur dans la formule", "ERREUR", MessageBoxButtons.OK, MessageBoxIcon.Error)
				Classeur.Close(False)
				Maplage=Nothing
				Feuille=Nothing
				Classeur=Nothing
				AppExcel.Quit()
				AppExcel=Nothing
				Exit Sub
			End If
		Else
			MaPlage.Value="#N/A"		
		End If
		'Tracé de la courbe
		Dim Graphe As Microsoft.Office.Interop.Excel.chart=Classeur.Sheets.Add(Classeur.Sheets(1), ,1,Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATChart)
		Graphe.ChartType=Excel.XlChartType.xlXYScatterLinesNoMakersGraphe.SetSourceData(Feuille.Cells(1,1).Resize(102,2),Excel.XlRowCol.xlColums)
		'Récupération du presse-papiers dans le picturebox
		Dim data As IDataObject
		data=Clipboard.GetDataObject
		Dim bmap As System.Drawing.Bitmap
		If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
			bmap=CType(data.GetData(GetType(System.Drawing.Bitmap)),System.Drawing.Bitmap)
			Me.PictureBox1.Image=bmap
			Me.PictureBox1.SizeMode=PictureBoxSizeMode.StretchImage			
		End If
		'Fermeture propre d'Excel
		Classeur.Close(False)
		Maplage=Nothing
		Feuille=Nothing
		Classeur=Nothing
		AppExcel.Quit()
		AppExcel=Nothing
	End Sub
	Private Sub txtMini_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtMini.KeyPress
		Dim c As Char
		c=e.KeyChar
		If Not (Char.IsDigit(c) Or Char.IsControl(c)) Then 
			e.Handled=True
		End If		
	End Sub
	Private Sub txtMaxi_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtMaxi.KeyPress
		Dim c As Char
		c=e.KeyChar
		If Not (Char.IsDigit(c) Or Char.IsControl(c)) Then 
			e.Handled=True
		End If		
	End Sub
End Module
Je n'utilise pas VB 2005 express mais SharpDevelop 2.2. Je débute en VB.NET, j'étais sur du C++ avant.

Alors l'erreur qu'il m'indique est 'Me' n'est pas valide dans un module. (BC32001). Et ça dans les trois cas où 'Me' est présent.

Comme je ne m'y connais pas trop en .NET, je bloque.

Ps : le code à pour but de créer un graph sous excel via le presse papier.