Connection MS.Excel + Word With Visual Studio
hal yang dilakukan pertama adalah buat data diexcel dan word seperti berikut :
khusus untuk di word kita harus melakukan bookmark. dengan cara insert bookmark yang berada di tombol toolbar :
setelah itu kita tinggal design di visualnya:
setelah kita input datanya kita tinggal klik tombol Generate excel + Word maka secara otomatis data yang kita input akan keluar di program excel begitu juga ms.word :
dan berikut codingnya :
'import Excel
Imports Excel = Microsoft.Office.Interop.Excel
'Import Word
Imports Word = Microsoft.Office.Interop.Word
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'block code ini digunakan untuk melakukan automation pada Dokumen MS. Excel
Dim AppExcel As New Excel.Application
Dim wrkExcel As Excel.Workbook
AppExcel.Visible = True
wrkExcel = AppExcel.Workbooks.Open("C:\Users\Toshiba\Documents\Visual Studio 2010\New folder\CertificateApps\dataExcel.xlsx")
AppExcel.Range("B8").Insert()
AppExcel.Range("C8").Insert()
AppExcel.Range("D8").Insert()
AppExcel.Range("E8").Insert()
AppExcel.Range("F8").Insert()
AppExcel.Range("G8").Insert()
AppExcel.Range("H8").Insert()
AppExcel.Range("I8").Insert()
AppExcel.Range("J8").Insert()
AppExcel.Range("B8").Value = txtno.Text
AppExcel.Range("C8").Value = txtnama.Text
AppExcel.Range("D8").Value = txtccna.Text
AppExcel.Range("E8").Value = txtlinux.Text
AppExcel.Range("F8").Value = txthacking.Text
AppExcel.Range("G8").Value = txtoracle.Text
AppExcel.Range("H8").Value = txtgrade.Text
AppExcel.Range("I8").Value = txtwaktu.Text
AppExcel.Range("J8").Value = txttanggal.Text
wrkExcel.Save()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Block Code ini digunakan untuk melakukan automation pada Dokumen word
Dim appku As New Word.Application
Dim objku As New Word.Document
objku = appku.Documents.Open("C:\Users\Toshiba\Documents\Visual Studio 2010\New folder\CertificateApps\dataWord.docx")
objku.Bookmarks("no").Select()
appku.Selection.TypeText(txtno.Text)
appku.Visible = True
objku.Bookmarks("nama").Select()
appku.Selection.TypeText(txtnama.Text)
appku.Visible = True
objku.Bookmarks("ccna").Select()
appku.Selection.TypeText(txtccna.Text)
appku.Visible = True
objku.Bookmarks("linux").Select()
appku.Selection.TypeText(txtlinux.Text)
appku.Visible = True
objku.Bookmarks("hacking").Select()
appku.Selection.TypeText(txthacking.Text)
appku.Visible = True
objku.Bookmarks("oracle").Select()
appku.Selection.TypeText(txtoracle.Text)
appku.Visible = True
objku.Bookmarks("grade").Select()
appku.Selection.TypeText(txtgrade.Text)
appku.Visible = True
objku.Bookmarks("waktu").Select()
appku.Selection.TypeText(txtwaktu.Text)
appku.Visible = True
objku.Bookmarks("tanggal").Select()
appku.Selection.TypeText(txttanggal.Text)
appku.Visible = True
End Sub
End Class
No comments:
Post a Comment