Вы находитесь на странице: 1из 2

private export2excel_click()

If cmbDept.Text = "" Then


MsgBox "Pilih Dept yg Akan Di export !!"
Else
Dim xls As New Excel.Application
Dim posx As Integer
SQL = "select * from Maskar where Dept = '" & cmbDept.Text & "' order by NoK
ar"
Set Rs_Karyawan = New ADODB.Recordset
Rs_Karyawan.Open SQL, KonekDb, adOpenDynamic, adLockOptimistic
Rs_Karyawan.MoveFirst
With xls
.Workbooks.Open App.Path & "\DataExcel\MaskarExp.xls", , True
.Sheets("Maskar").Select
posx = 4
Rs_Karyawan.MoveFirst
Do While Rs_Karyawan.EOF = False
.Cells(posx, 1) = Rs_Karyawan!NoKar
.Cells(posx, 2) = Rs_Karyawan!NamaKar
.Cells(posx, 3) = Rs_Karyawan!divno
.Cells(posx, 4) = Rs_Karyawan!Dept
.Cells(posx, 5) = Rs_Karyawan!Sect
.Cells(posx, 6) = Rs_Karyawan!Rank
.Cells(posx, 7) = Rs_Karyawan!Status
.Cells(posx, 8) = Rs_Karyawan!TglMasuk
.Cells(posx, 9) = Rs_Karyawan!Anak
.Cells(posx, 10) = Rs_Karyawan!Shift
.Cells(posx, 11) = Rs_Karyawan!Jenkel
.Cells(posx, 12) = Rs_Karyawan!ShDept
.Cells(posx, 13) = Rs_Karyawan!KGroup
.Cells(posx, 14) = Rs_Karyawan!TglLahir
.Cells(posx, 15) = Rs_Karyawan!DirIndir
.Cells(posx, 16) = Rs_Karyawan!TglOut
.Cells(posx, 17) = Rs_Karyawan!Pendidikan
.Cells(posx, 18) = Rs_Karyawan!Agama
.Cells(posx, 19) = Rs_Karyawan!Address_Now
.Cells(posx, 20) = Rs_Karyawan!Address_Now1
.Cells(posx, 21) = Rs_Karyawan!Address_Now2
.Cells(posx, 22) = Rs_Karyawan!Notlp_HP
.Cells(posx, 23) = Rs_Karyawan!Address_lama
.Cells(posx, 24) = Rs_Karyawan!nm_istri_suami
.Cells(posx, 25) = Rs_Karyawan!tglLhir_istri_suami
.Cells(posx, 26) = Rs_Karyawan!nm_Anak1
.Cells(posx, 27) = Rs_Karyawan!tglLhr_A1
.Cells(posx, 28) = Rs_Karyawan!nm_Anak2
.Cells(posx, 29) = Rs_Karyawan!tglLhr_A2
.Cells(posx, 30) = Rs_Karyawan!nm_Anak3
.Cells(posx, 31) = Rs_Karyawan!tglLhr_A3
.Cells(posx, 32) = Rs_Karyawan!nm_ayah
.Cells(posx, 33) = Rs_Karyawan!tglLhr_Ayah
.Cells(posx, 34) = Rs_Karyawan!nm_ibu
.Cells(posx, 35) = Rs_Karyawan!tglLhr_ibu
.Cells(posx, 36) = Rs_Karyawan!Addres_emergency
.Cells(posx, 37) = Rs_Karyawan!Family_in_surindo
posx = posx + 1
Rs_Karyawan.MoveNext
Loop

ChDir App.Path & "\Report"


.ActiveWorkbook.SaveAs FileName:=App.Path & "\Report\Maskar" & cmbDept.T
ext & "-" & Format(Date, "ddmmyyyy") & ".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=F
alse _
, CreateBackup:=False
.Visible = True
'.ActiveWindow.SelectedSheets.PrintPreview
.Application.DisplayAlerts = False
'.Quit
End With
End If
Unload Me
end sub

Вам также может понравиться