VB write to MS Word
'Membuka aplikasi Word dengan mengalokasikan memori untuk aplikasi word
Set MyWord = CreateObject("Word.Application")
Set WordDoc = MyWord.Documents.Add
'memyembunyikan word saat proses
MyWord.Visible = False
'page setup
WordDoc.PageSetup.TopMargin = 60
WordDoc.PageSetup.BottomMargin = 4
WordDoc.PageSetup.LeftMargin = 60
'Setting Font
MyWord.Selection.Font.Name = "ARIAL"
MyWord.Selection.Font.Size = 16
MyWord.Selection.Font.Bold = True
'Tulis apa yang mau di tulis
MyWord.Selection.TypeText "LAPORAN"
MyWord.Selection.TypeText vbCrLf & "Dalam bentuk MS Word"
MyWord.Selection.Font.Size = 10
MyWord.Selection.Font.Bold = False
'Membuat tabel
Set MyTable = MyWord.Selection.Tables.Add(MyWord.Selection.Range, 3, 4)
Set MyCols = MyTable.Columns
MyCols(1).Width = 120
MyCols(2).Width = 150
MyCols(3).Width = 120
MyCols(4).Width = 150
MyTable.Cell(1, 1).Range.Text = "NAMA"
MyTable.Cell(1, 1).Range.Font.Bold = True
MyTable.Cell(1, 2).Range.Text = ": " & LNAMA.Caption
MyTable.Cell(1, 3).Range.Text = "AGAMA"
MyTable.Cell(1, 3).Range.Font.Bold = True
MyTable.Cell(1, 4).Range.Text = ": " & LAGAMA.Caption
MyTable.Cell(2, 1).Range.Text = "USIA"
MyTable.Cell(2, 1).Range.Font.Bold = True
MyTable.Cell(2, 2).Range.Text = ": " & LUMUR.Caption
MyTable.Cell(2, 3).Range.Text = "PENDIDIKAN"
MyTable.Cell(2, 3).Range.Font.Bold = True
MyTable.Cell(2, 4).Range.Text = ": " & LPENDIDIKAN.Caption
MyTable.Cell(3, 1).Range.Text = "JENIS KELAMIN"
MyTable.Cell(3, 1).Range.Font.Bold = True
MyTable.Cell(3, 2).Range.Text = ": " & LJK.Caption
MyTable.Cell(3, 3).Range.Text = "PEKERJAAN"
MyTable.Cell(3, 3).Range.Font.Bold = True
MyTable.Cell(3, 4).Range.Text = ": " & LPEKERJAAN.Caption
MyWord.Visible = True
MyWord.Activate
No comments: