kali ini saya akan membuat perizinan mobil menggunakan visual basic di import ke ms. word dan ms. excel.
berikut foto form dan outputnya :
Berikut hasil imports ke ms. word menggunakan vb
Berikut hasil imports ke ms. excel menggunakan vb
berikut adalah coddingannya
Imports Microsoft.Office.Interop
Imports word = Microsoft.Office.Interop.Word
Public Class Form1
Dim app As New Excel.Application
Dim book As Excel.Workbook
Dim sheet As Excel.Worksheet
Dim myWordApp As New word.Application
Dim myworddoc As New word.Document
Private Sub btnexcel_Click(sender As Object, e As EventArgs) Handles btnexcel.Click
book = app.Workbooks.Open("C:\Users\ASUS\Documents\Book1.xlsx")
sheet = book.Sheets("Sheet1")
app.Range("A1").Value = "Nama"
app.Range("B1").Value = "NoKtp"
app.Range("C1").Value = "Alamat"
app.Range("D1").Value = "Hari"
app.Range("E1").Value = "Tanggal"
app.Range("A2").Value = txtnama.Text
app.Range("B2").Value = txtnoktp.Text
app.Range("C2").Value = txtalamat.Text
app.Range("D2").Value = txthari.Text
app.Range("E2").Value = txttanggal.Text
book.Save()
app.Quit()
End Sub
Private Sub btnkeluar_Click(sender As Object, e As EventArgs) Handles btnkeluar.Click
Dim a As String
a = MsgBox("Yakin Keluar?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Konfirmasi")
If a = vbYes Then
Me.Close()
End If
End Sub
Private Sub btnmulai_Click(sender As Object, e As EventArgs) Handles btnmulai.Click
Me.txtnama.Text = ""
Me.txtnoktp.Text = ""
Me.txtalamat.Text = ""
Me.txthari.Text = ""
Me.txttanggal.Text = ""
Me.txtnama.Focus()
End Sub
Private Sub btnword_Click(sender As Object, e As EventArgs) Handles btnword.Click
Dim mywordapp As New word.Application
Dim myworddoc As New word.Document
myworddoc = mywordapp.Documents.Open("C:\Users\ASUS\Documents\Surat Perizinan Mobil.docx")
myworddoc.Bookmarks("Nama").Select()
mywordapp.Selection.Paragraphs.Alignment = word.WdParagraphAlignment.wdAlignParagraphLeft
mywordapp.Selection.Font.Name = "Times New Roman"
mywordapp.Selection.Font.Size = 12
mywordapp.Selection.TypeText(txthari.Text)
myworddoc.Bookmarks("NoKtp").Select()
mywordapp.Selection.Paragraphs.Alignment = word.WdParagraphAlignment.wdAlignParagraphLeft
mywordapp.Selection.Font.Name = "Times New Roman"
mywordapp.Selection.Font.Size = 12
mywordapp.Selection.TypeText(txttanggal.Text)
myworddoc.Bookmarks("Alamat").Select()
mywordapp.Selection.Paragraphs.Alignment = word.WdParagraphAlignment.wdAlignParagraphLeft
mywordapp.Selection.Font.Name = "Times New Roman"
mywordapp.Selection.Font.Size = 12
mywordapp.Selection.TypeText(txttempat.Text)
myworddoc.Bookmarks("Hari").Select()
mywordapp.Selection.Paragraphs.Alignment = word.WdParagraphAlignment.wdAlignParagraphLeft
mywordapp.Selection.Font.Name = "Times New Roman"
mywordapp.Selection.Font.Size = 12
mywordapp.Selection.TypeText(txtnama.Text)
myworddoc.Bookmarks("Tanggal").Select()
mywordapp.Selection.Paragraphs.Alignment = word.WdParagraphAlignment.wdAlignParagraphLeft
mywordapp.Selection.Font.Name = "Times New Roman"
mywordapp.Selection.Font.Size = 12
mywordapp.Selection.TypeText(txtnpm.Text)
myworddoc.SaveAs("C:\Users\ASUS\Documents\Surat Perizinan Mobil.docx")
mywordapp.Visible = True
End Sub
End Class



Tidak ada komentar:
Posting Komentar