Cara mengimpor informasi dari Excel ke Visual Basic 6

Membuat informasi di Excel lebih mudah daripada di VB6, jadi terkadang lebih praktis untuk mengimpor informasi dari Excel ke VB6.

Langkah 1

Mulai proyek Visual Basic baru.

Langkah 2

Tambahkan kotak daftar dan tombol perintah ke formulir.

Langkah 3

Pilih "Project Menu" dan kemudian pilih opsi "Referensi". Dari sana, pilih "Microsoft Excel Library".

Langkah 4

Masukkan kode berikut: Private Sub Command1_Click () Dim objXLApp As Excel.Application Dim intLoopCounter As Integer

Set objXLApp = New Excel.Application

Dengan objXLApp .Workbooks.Open "C: \ File.xls" .Workbooks (1) .Worksheets (1) .Pilih

Untuk intLoopCounter = 1 Ke CInt (.ActiveSheet.Cells.SpecialCells (xlCellTypeLastCell) .Row) List1.AddItem .Range ("To" & intLoopCounter) Next intLoopCounter

.Workbooks (1). Tutup False .Quit End With

Set objXLApp = Tidak Ada Sub Akhir

Langkah 5

Ubah "C: \ File.xls" menjadi nama file Excel Anda. Ini sekarang akan mengimpor informasi dari spreadsheet Excel Anda.