mas jenar, utk coding yang anda berikan udh saya coba & berhasil tapi ketika excelnya sy tutup & buttom1nya sy klik lagi (membuka kembali) koq tidak bisa ya, mohon pencerahannya.
thx
2006/1/11, Jenar Suseno <[EMAIL PROTECTED]>:
Sebagai alternatif aja...aku biasa pake ini :
di general form tambahkan ini :
Dim objapp As Excel.Application
Dim objbook As Excel.Workbook
Dim objsheet1 As Excel.Worksheet
Trus di bottom1 click (misalnya) isikan :
' disini proses bikin recorset
' data yang akan di export ke excel,
' recordsetnya berinama misal rst
Set objapp = New Excel.Application
objapp.Visible = True 'If you want to see it
work
' objapp.Visible = false 'If you don't want to
see it work
Set objbook = objapp.Workbooks.Add
Set objsheet1 = objapp.Worksheets.Add
'Isi nama sheet excel
objsheet1.Name = Left(Trim("Hasil Export"), 30)
'Atur judul & kolom
objsheet1.Cells(1, 2).Value = "Judul I"
objsheet1.Cells(2, 2).Value = "Judul II"
objsheet1.Cells(4, 2).Value =
UCase(Trim(rst(0).Name))
objsheet1.Cells(4, 3).Value =
UCase(Trim(rst(1).Name))
objsheet1.Cells(4, 4).Value =
UCase(Trim(rst(2).Name))
'Copy semua data recorsert ke excel
objsheet1.Range("B5").CopyFromRecordset rst
'Bersihkan memori
Set objsheet1 = Nothing
Set objapp = Nothing
' akhir code
kali aja bermanfaat...
--- Asral Sukma <[EMAIL PROTECTED]> wrote:
> Mau transfer dari rekening mana dulu mas jos...
> hehehe
>
> saya coba bantu ya...
>
> Private Sub export_excel()
>
> Dim xlApp As Object
> Dim xlWb As Object
> Dim xlWs As Object
>
> Dim recArray As Variant
>
> Dim strDB As String
> Dim fldCount As Integer
> Dim recCount As Long
> Dim iCol As Integer
> Dim iRow As Integer
> Dim rs As ADODB.Recordset
> Set rs = New ADODB.Recordset
>
> rs.Open sql, dbbph, adOpenStatic, adLockOptimistic
> rs.MoveLast
> rs.MoveFirst
>
> Set xlApp = CreateObject("Excel.Application")
> Set xlWb = xlApp.Workbooks.Add
> Set xlWs = xlWb.Worksheets("Sheet1")
>
>
> xlApp.Visible = True
> xlApp.UserControl = True
>
> fldCount = rs.Fields.Count
> For iCol = 1 To fldCount
> xlWs.cells(1, iCol).Value = rs.Fields(iCol -
> 1).Name
> Next
>
>
> If Val(Mid(xlApp.Version, 1, InStr(1,
> xlApp.Version, ".") - 1)) > 8 Then
>
>
> xlWs.cells(2, 1).CopyFromRecordset rs
>
> Else
>
> recArray = rs.GetRows(rs.RecordCount)
>
> recCount = UBound(recArray, 2) + 1 '+ 1
> since 0-based array
>
> For iCol = 0 To fldCount - 1
> For iRow = 0 To recCount - 1
> ' Take care of Date fields
> If IsDate(recArray(iCol, iRow)) Then
> recArray(iCol, iRow) =
> Format(recArray(iCol, iRow))
> ' Take care of OLE object fields or
> array fields
> ElseIf IsArray(recArray(iCol, iRow))
> Then
> recArray(iCol, iRow) = "Array
> Field"
> End If
> Next iRow 'next record
> Next iCol 'next field
>
> xlWs.cells(2, 1).Resize(recCount,
> fldCount).Value = _
> TransposeDim(recArray)
> End If
>
> xlApp.Selection.CurrentRegion.Columns.AutoFit
> xlApp.Selection.CurrentRegion.Rows.AutoFit
>
> Set xlWs = Nothing
> Set xlWb = Nothing
> Set xlApp = Nothing
> End Sub
>
>
> Kepanjangan ga ya???
> mungkin tmen2 yg lain punya yg lebih
> pendek.....hehehe
>
> semoga membantu
>
> --aL--
> joseph jos <[EMAIL PROTECTED]> wrote:
> rekan rekan,mohon bantuannya nih, saya ingin
> mentransfer hasil laporan tetapi ditampilkan di
> excel.
> Terima kasih atas bantuannya.
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam
> protection around
> http://mail.yahoo.com
>
>
> Wahana Programmer Indonesia Links:
>
>
>
>
>
>
> SPONSORED LINKS
> Programmer Indonesia Basic programming
> language Computer programming languages
> Programming languages Java programming language
>
> ---------------------------------
> YAHOO! GROUPS LINKS
>
>
> Visit your group "Programmer-VB" on the web.
>
> To unsubscribe from this group, send an email
> to:
> [EMAIL PROTECTED]
>
> Your use of Yahoo! Groups is subject to the
> Yahoo! Terms of Service.
>
>
> ---------------------------------
>
>
>
>
>
>
> ---------------------------------
> Yahoo! Photos
> Got holiday prints? See all the ways to get quality
> prints in your hands ASAP.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Wahana Programmer Groups Links
<*> Untuk mengunjungi sponsor milis ini, klik link berikut:
http://wahanaprogrammer.net
<*> Untuk menghubungi owner milis ini, kirim email ke:
[EMAIL PROTECTED]
<*> Konsultasi pemrogramman bisa chat disini:
Yahoo! Messenger: wahanaprogrammer
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Programmer-VB/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
Wahana Programmer Groups Links
<*> Untuk mengunjungi sponsor milis ini, klik link berikut:
http://wahanaprogrammer.net
<*> Untuk menghubungi owner milis ini, kirim email ke:
[EMAIL PROTECTED]
<*> Konsultasi pemrogramman bisa chat disini:
Yahoo! Messenger: wahanaprogrammer
YAHOO! GROUPS LINKS
- Visit your group "Programmer-VB" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
