Home > Software engineering >  About vb call excell
About vb call excell

Time:10-09

I want to do a procedure: to excel in the program, below written content in the text, press sure he will be added to the excel, and excel will add data interface,

Then the Internet under a can show, but there are a lot of is not in conformity with the, after the first run of excel can display but excel the gender, name from nowhere to

The code is as follows:
Option Explicit
Dim xlApp As Excel. Class defined Excel Application '
Dim xlBook As Excel. The Workbook 'class definition artifacts book
Dim xlsheet As Excel. The Worksheet 'definition Worksheet class

Private Sub Command1_Click ()
Dim I As an Integer, j As Integer
The Set xlApp=CreateObject (" Excel. Application ") 'create Excel Application class
XlApp. Visible=False 'set of EXCEL is not currently Visible
The Set xlBook=xlApp. Workbooks. Open (App) Path & amp; "\ data. XLS") 'open the EXCEL workbook
Set xlsheet=xlBook. Worksheets (1) the 'open the EXCEL Worksheets
'xlsheet. Activate to Activate worksheet
Dim litem
For I=2 To 7 'row/record number

Set litem=ListView1. ListItems. The Add ()
Litem. Text=xlsheet. Cells (I, 1)
Litem. SubItems (1)=xlsheet. Cells (I, 2)
Litem. SubItems (2)=xlsheet. Cells (I, 3)
Litem. SubItems (3)=xlsheet. Cells (I, 4)
'MsgBox xlsheet. Cells (I, j)

Next
XlBook. Close (True) 'Close EXCEL workbook
XlApp. Quit 'close EXCEL
The Set xlApp release EXCEL object
=Nothing '
End Sub

CodePudding user response:

Option Explicit
Dim xlApp As Excel. Class defined Excel Application '
Dim xlBook As Excel. The Workbook 'class definition artifacts book
Dim xlsheet As Excel. The Worksheet 'definition Worksheet class
Private sub form_load ()
The Set xlApp=CreateObject (" Excel. Application ") 'create Excel Application class
XlApp. Visible=true 'set of EXCEL Visible
The Set xlBook=xlApp. Workbooks. Add
Set xlsheet=xlBook. Worksheets (1) the 'open the EXCEL Worksheets
'xlsheet. Activate to Activate worksheet
End sub
Private Sub Command1_Click ()
'to the first cell assignment
Xlsheet. Cells (1, 1)="sofhoisfhoisf
"End Sub
Private form_unload ()
The set xlsheet=nothing
The set xlbook=nothing
Xlapp. Quit
The set xlapp=nothing
End sub
  •  Tags:  
  • VBA
  • Related