Dim ExcelApp As New Microsoft.Office.Interop.Excel.Application
Dim MyExcelBook As Microsoft.Office.Interop.Excel.Workbook
Dim AppWord As Microsoft.Office.Interop.Word.Application
Dim DocWord As Microsoft.Office.Interop.Word.Document
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MyExcelBook = ExcelApp.Workbooks.Open("D:\tugas vb\Book1.xlsx")
ExcelApp.Range("A6").Value = TextBox1
ExcelApp.Range("B6").Value = ComboBox1
ExcelApp.Range("C6").Value = ComboBox2
ExcelApp.Range("D6").Value = TextBox4
ExcelApp.Range("E6").Value = TextBox5
MyExcelBook.SaveAs("D:\tugas vb\Book1.xlsx")
ExcelApp.Visible = True
DocWord = AppWord.Documents.Open("D:\tugas vb\Data pembayaran.docx")
DocWord.Bookmarks("Nama barang").Select()
AppWord.Selection.TypeText(TextBox1.Text)
DocWord.Bookmarks("Kode barang").Select()
AppWord.Selection.TypeText(ComboBox1.Text)
DocWord.Bookmarks("Jumlah pembelian").Select()
AppWord.Selection.TypeText(ComboBox2.Text)
DocWord.Bookmarks("Haraga satuan").Select()
AppWord.Selection.TypeText(TextBox4.Text)
DocWord.Bookmarks("Jumlah harga").Select()
AppWord.Selection.TypeText(TextBox5.Text)
DocWord.SaveAs2("D:\tugas vb\Data pembayaran.docx")
AppWord.Visible = True
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("001")
ComboBox1.Items.Add("002")
ComboBox1.Items.Add("003")
ComboBox1.Items.Add("004")
ComboBox1.Items.Add("005")
ComboBox2.Items.Add("1")
ComboBox2.Items.Add("2")
ComboBox2.Items.Add("3")
ComboBox2.Items.Add("4")
ComboBox2.Items.Add("5")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text = "001" Then
TextBox1.Text = "teh kotak"
TextBox4.Text = "5000"
End If
If ComboBox1.Text = "002" Then
TextBox1.Text = "frestea"
TextBox4.Text = "5000"
End If
If ComboBox1.Text = "003" Then
TextBox1.Text = "pocari sweat"
TextBox4.Text = "5000"
End If
If ComboBox1.Text = "004" Then
TextBox1.Text = "coca cola"
TextBox4.Text = "5000"
End If
If ComboBox1.Text = "005" Then
TextBox1.Text = "Fanta"
TextBox4.Text = "5000"
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
If ComboBox2.Text = "1" Then
TextBox5.Text = "5000"
End If
If ComboBox2.Text = "2" Then
TextBox5.Text = "10000"
End If
If ComboBox2.Text = "3" Then
TextBox5.Text = "15000"
End If
If ComboBox2.Text = "4" Then
TextBox5.Text = "20000"
End If
If ComboBox2.Text = "5" Then
TextBox5.Text = "25000"
End If
End Sub
End Class
Tidak ada komentar:
Posting Komentar