Personal Mind of ASEP

Sepercik Rasa yang Tercurah

Transfer dari FlexGerid ke excel di vb 6

kemaren2 gw bikin gimana caranya tranfer data yang udah gw tampilin di flexgrid ke dalam excel, setelah gw acak planet-source-code baru dapat deh😀 , programnya sih cukup sederhana,

Langkah pertama masukin dulu Ms. Excel Object Library di preference nya vb yang ada di menu Project -> preferences trus masukin deh kode-kode kaya ginih :

Isikan ini di bagian deklarasi

Dim msExcel As Excel.Application
Dim msExcelWorkBook As Workbook
Dim msExcelWorkSheet As Worksheet
Dim msExcelRange As Range

Trus Masukan kode ini di bagian tombol untuk eksekusi perintah (Command Button)

Private Sub CmdExc_Click()
On Error GoTo heLL
Dim j, i
Set msExcel = CreateObject(“Excel.Application”)
msExcel.Visible = True
Set msExcelWorkBook = msExcel.Workbooks.Add
Set msExcelWorkSheet = msExcelWorkBook.Worksheets(1)
If Val(msExcel.Application.Version) >= 8 Then
Set msExcelWorkSheet = msExcel.ActiveSheet
Else
Set msExcelWorkSheet = msExcel
End If

i = 1
j = 1

For i = 0 To MSFlexGrid1.Rows – 1
MSFlexGrid1.Row = i
For j = 0 To MSFlexGrid1.Cols – 1
MSFlexGrid1.Col = j
msExcelWorkSheet.Cells(i + 1, j + 1) = MSFlexGrid1.Text
Next
Next
MsgBox “Transfer Data Berhasil”, vbInformation
Exit Sub
heLL:
If Err.Number > 0 Then
MsgBox “Ada kesalahan dalam transfer ke EXCEL harap di ulang kembali, OK !!”, vbCritical
Exit Sub
End If

End Sub

udah deh tampilan yang ada di flexgrid akan pindah di excel🙂, dan biasanya error akan muncul ketika proses pemindahan data dari grid ke excel belum selesai kita sudah eksekusi perintah lainnya

February 16, 2006 - Posted by | Uncategorized

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: