| 12
 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
 
 | Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
    Dim APP As New Excel.Application
    Dim worksheet As Excel.Worksheet
    Dim workbook As Excel.Workbook
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'FormBorderStyle = Windows.Forms.FormBorderStyle.None
        workbook = APP.Workbooks.Open("I:\x.xlsx")
        worksheet = workbook.Worksheets("Feuil1")
        APP.Visible = True 'Optionnel
 
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        worksheet.Cells(1, 1).Value = TextBox1.Text
        worksheet.Cells(1, 2).Value = TextBox2.Text
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        worksheet.Cells(5, 6).Formula() = "=SUM(A1:B1)"
 
 
 
    End Sub
    Private Sub Form1_FormClosed(ByVal sender As System.Object, _
 ByVal e As System.Windows.Forms.FormClosedEventArgs) _
  'Handles MyBase.FormClosed
 
        'workbook.Save()
        'workbook.Close()
        'APP.Quit()
 
    End Sub
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        worksheet.Cells(1, 1).Value = 56
        worksheet.Cells(1, 7).Value = "ouio"
    End Sub
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.Close()
 
 
    End Sub
 
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Form2.Show() ' ouvrir une form
        Me.Close() ' c'est pour fermer une forme
 
 
    End Sub
End Class
 
tous fonctionne tres bien mais quand je passe a la form2 je n'arrive a ecrire dans le fichier excel nommé x
voici le code :
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form2
    Dim app As Excel.Application
    Dim worksheet As Excel.Worksheet
    Dim workbook As Excel.Workbook
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.Show()
        Me.Close()
 
 
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 
        worksheet.Cells(1, 7).Value = "ouio"
 
    End Sub
 
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        workbook = app.Workbook("I:\x.xlsx")
        worksheet = workbook.Worksheets("Feuil1")
    End Sub
 
End Class |