Senin, 08 Februari 2016

Cara Membuat Program Export Excel di Visual Basic 6.0



1.      Tambahkan satu buah module dan simpan dengan nama ModExport
2.      Ketikkan script berikut pada ModExport:

artikel terkait : http://komtipstrik.blogspot.co.id/2016/02/memulai-pemrograman-di-visual-basic-60.html
1
Dim objXL As New Excel.Application
Dim wbXL As New Excel.Workbook
Dim wsXL As New Excel.Worksheet
Dim intRow As Integer ' counter
Dim intCol As Integer ' counter

Public Sub SimpanKeExcelDinamis(TheFlexgrid As VSFlexGrid, _
  TheRows As Integer, TheCols As Integer, _
  Optional GridStyle As Integer = 1, Optional WorkSheetName _
  As String)

If Not IsObject(objXL) Then
    MsgBox "You need Microsoft Excel to use this function", _
       vbExclamation, "Print to Excel"
    Exit Sub
End If


On Error Resume Next

objXL.Visible = True
Set wbXL = objXL.Workbooks.Add
Set wsXL = objXL.ActiveSheet
   
For intRow = 1 To TheRows
    For intCol = 1 To TheCols
        With TheFlexgrid
            wsXL.Cells(intRow, intCol).Value = "'" & .TextMatrix(intRow - 1, intCol - 1) & " "
        End With
    Next
Next

For intCol = 1 To TheCols
    wsXL.Columns(intCol).AutoFit
Next

With wsXL
    If Not WorkSheetName = "" Then
        .Name = WorkSheetName
        .SaveAs App.Path & "\Excel File\" & WorkSheetName
    End If
End With
End Sub
Cat:


  1. Atur startup object dari menu Project - Project Properties
  2. Pada Tab General dan pilihan Startup Object, pilih Sub Main, Klik OK
  3. Klik Ikon Simpan
  4. Jalankan program dengan mengklik menu Run - Start atau klik ikon         pada toolbar atau tekan F5
  5. Jika berhasil tidak akan terjadi error (debug) dan sebaliknya.




artikel terkait :  http://komtipstrik.blogspot.co.id/2016/02/pembuatan-module-pada-pemrograman.html


Load disqus comments

0 komentar