Advertisement
rikokurniawan

Prosedur Export Excel/Membuat Laporan Ke excel

Jan 18th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub mngajibulanan_Click()
  2. X = MsgBox("Anda yakin Cetak Laporan Gaji Bulanan?", vbQuestion + vbYesNo, "Konfirmasi Cetak..")
  3.  If X = vbYes Then
  4.     'bagian deklarasi
  5. Dim xlapp As Excel.Application
  6.  Dim xlwb As Excel.Workbook
  7.  Dim xlsheet As Excel.Worksheet
  8.  
  9.  'koneksi ke tabel
  10. Set rs = New ADODB.Recordset
  11.  rs.CursorLocation = adUseClient
  12.  rs.Open "select * from carigaji", db, adOpenStatic, adLockReadOnly
  13.  
  14.  'bagian eksekusi
  15. Set xlapp = New Excel.Application
  16.  Set xlwb = xlapp.Workbooks.Add
  17.  Set xlsheet = xlwb.Worksheets(1)
  18.  xlapp.Visible = True
  19.  
  20.  'buat judul tabel
  21. With xlsheet
  22.    .Cells(1, 2).Value = "LAPORAN PENGGAJIAN PT.ABC"
  23.    .Cells(3, 1).ColumnWidth = 12
  24.    .Cells(3, 1).Value = "NIP"
  25.    .Cells(3, 2).ColumnWidth = 20
  26.    .Cells(3, 2).Value = "NAMA PEGAWAI"
  27.    .Cells(3, 3).ColumnWidth = 11
  28.    .Cells(3, 3).Value = "GOLONGAN"
  29.    .Cells(3, 4).ColumnWidth = 11
  30.    .Cells(3, 4).Value = "GAJI POKOK"
  31.    .Cells(3, 5).Value = "TJ. ANAK"
  32.    .Cells(3, 6).ColumnWidth = 15
  33.    .Cells(3, 6).Value = "TJ. PERKAWINAN"
  34.    .Cells(3, 7).ColumnWidth = 11
  35.    .Cells(3, 7).Value = "GAJI KOTOR"
  36.    .Cells(3, 8).ColumnWidth = 10.3
  37.    .Cells(3, 8).Value = "PAJAK"
  38.    .Cells(3, 9).ColumnWidth = 11
  39.    .Cells(3, 9).Value = "GAJI BERSIH"
  40.  End With
  41.  
  42.  'BAGIAN PENAMPILAN DATA
  43. br = 4
  44.  totalgaji = 0
  45.  With xlsheet
  46.   rs.MoveFirst
  47.   For i = 1 To rs.RecordCount
  48.      .Cells(br, 1) = rs!NIP
  49.      .Cells(br, 2) = rs!NAMA
  50.      .Cells(br, 3) = rs!GOL
  51.      .Cells(br, 4) = rs!GAJIPOKOK
  52.      .Cells(br, 5) = rs!TJANAK
  53.      .Cells(br, 6) = rs!TJKAWIN
  54.      .Cells(br, 7) = rs!GAJIKOTOR
  55.      .Cells(br, 8) = rs!PAJAK
  56.      .Cells(br, 9) = rs!GAJIBERSIH
  57.      totalgaji = totalgaji + rs!GAJIBERSIH
  58.      rs.MoveNext
  59.      br = br + 1
  60.   Next
  61.   .Cells(br, 8) = "TOTAL GAJI"
  62.   .Cells(br, 9) = totalgaji
  63.  End With
  64.  End If
  65.  
  66.  
  67.  
  68. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement