1. Pertama buatlah file Microsoft Word seperti dibawah ini
lalu setting boomarks untuk mengkoneksikan vb.net dan Ms.Wordnya
2. Langkah selanjutnya buat design form di visual basic seperti dibawah
lalu jangan lupa untuk mensetting references
3. Selanjutnya kita isi skrip untuk mengkoneksinaknya ke Ms.Word
sskripnya seperti dibawah :
Imports word = Microsoft.Office.Interop.Word
Imports excel = Microsoft.Office.Interop.Excel
Public Class
Form1
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim
myWordApp As New
word.Application
Dim
myWordDoc As New
word.Document
Dim
hasil As New Integer
myWordDoc = myWordApp.Documents.Open("C:\Users\Secret\Documents\bookmarknanda.docx")
myWordDoc.Bookmarks("nama").Select()
myWordApp.Selection.Paragraphs.Alignment =
word.WdParagraphAlignment.wdAlignParagraphLeft
myWordApp.Selection.Font.Name = "Calibri"
myWordApp.Selection.Font.Size = 12
myWordApp.Selection.TypeText(TextBox1.Text)
myWordDoc.Bookmarks("noujian").Select()
myWordApp.Selection.TypeText(TextBox2.Text)
myWordDoc.Bookmarks("mtk").Select()
myWordApp.Selection.TypeText(TextBox3.Text)
myWordDoc.Bookmarks("bind").Select()
myWordApp.Selection.TypeText(TextBox4.Text)
myWordDoc.Bookmarks("bing").Select()
myWordApp.Selection.TypeText(TextBox5.Text)
myWordDoc.Bookmarks("ipa").Select()
myWordApp.Selection.TypeText(TextBox6.Text)
myWordDoc.Bookmarks("hasil").Select()
myWordApp.Selection.TypeText(TextBox7.Text)
hasil = (Val(TextBox3.Text) +
Val(TextBox4.Text) + Val(TextBox5.Text) + Val(TextBox6.Text)) / 4
If
hasil >= 60 Then
TextBox7.Text = "LULUS"
myWordDoc.Bookmarks("hasil").Select()
myWordApp.Selection.Paragraphs.Alignment =
word.WdParagraphAlignment.wdAlignParagraphCenter
myWordApp.Selection.Font.Name = "Calibri"
myWordApp.Selection.Font.Size = 20
myWordApp.Selection.TypeText("LULUS")
myWordDoc.SaveAs("C:\Users\Secret\Documents\bookmarknanda.docx")
Else
TextBox7.Text = "TIDAK LULUS"
myWordDoc.Bookmarks("hasil").Select()
myWordApp.Selection.Paragraphs.Alignment =
word.WdParagraphAlignment.wdAlignParagraphCenter
myWordApp.Selection.Font.Name = "Calibri"
myWordApp.Selection.Font.Size = 20
myWordApp.Selection.TypeText("TIDAK LULUS")
myWordDoc.SaveAs("C:\Users\Secret\Documents\bookmarknanda.docx")
End If
myWordApp.Visible = True
myWordApp.Quit()
End Sub
- maka setelah di run akan muncul seperti ini
dan setelah dibuka Ms.Word akan muncul seperti gambar dibawah
selesai untuk mengkoneksikan ke Ms.Word
Dan sekarang saya akan menjelaskan lagkah untuk memgkoneksikan ke Ms.Excel
1. Buatlah form di excel, lalu setting referencenya
2.lalu masukkan skrip seperti dibawah ini :
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
Button2.Click
Dim
myExcelApp As New
excel.Application
Dim
myExcelBook As excel.Workbook
Dim
hasil As New Integer
myExcelBook = myExcelApp.Workbooks.Open("c:\data.xlsx")
myExcelApp.Range("A1").Value = "NAMA"
myExcelApp.Range("B1").Value = "NO.UJIAN"
myExcelApp.Range("C1").Value = "MATEMATIKA"
myExcelApp.Range("D1").Value = "B.INDONESIA"
myExcelApp.Range("E1").Value = "B.INGGRIS"
myExcelApp.Range("F1").Value = "IPA"
myExcelApp.Range("G1").Value = "HASIL"
myExcelApp.Range("A2").Value = TextBox1.Text
myExcelApp.Range("B2").Value = TextBox2.Text
myExcelApp.Range("C2").Value = TextBox3.Text
myExcelApp.Range("D2").Value = TextBox4.Text
myExcelApp.Range("E2").Value = TextBox5.Text
myExcelApp.Range("F2").Value = TextBox6.Text
myExcelApp.Range("G2").Value = TextBox7.Text
hasil = (Val(TextBox3.Text) +
Val(TextBox4.Text) + Val(TextBox5.Text) + Val(TextBox7.Text)) / 4
If
hasil >= 60 Then
TextBox7.Text = "LULUS"
myExcelApp.Range("G2").Value = "LULUS"
Else
TextBox7.Text = "TIDAK LULUS"
myExcelApp.Range("G2").Value = "TIDAK
LULUS"
End If
myExcelApp.Visible = True
myExcelApp.Quit()
End Sub
End Class
3. setelah di running maka akan muncul seperti ini
dan setelah dibuka di excel maka akan seperti ini
maka selesaiiii......