Home > Software engineering >  Vb reading EXCEL data errors
Vb reading EXCEL data errors

Time:12-23

Help help thank you
 Private Sub Command1_Click () 
Dim a (101) As the String
Dim I, j, b, As an Integer
Dim c As String
Dim xlsApp As Excel. Application
Dim xlsWorkbook As Excel. The Workbook
Dim xlssheet As Excel. The Worksheet
The Set xlsApp=CreateObject (" Excel. Application ")

Set xlsWorkbook=xlsApp. Workbooks. Open (" e: \ after-sales service quantitative indicators ten-day reports. XLS ")
XlsApp. Visible=False
XlsApp. Range (" A1 "). Select
For j=0 To 5
For I=1 To 5
A (I)=xlsApp. ActiveCell. Offset (j, I - 1). The Value
Print the I;
Print "";
Print a (I)
Next I
Next j
C=xlssheet. UsedRange. Rows. The Count to perform to this statement will prompt error "object variables or variable is not set with block"
XlsWorkbook. Close
XlsApp. Quit
The Set xlssheet=Nothing
The Set xlsWorkbook=Nothing
The Set xlsApp=Nothing
End Sub

CodePudding user response:

Xlssheet. UsedRange. Rows. Count
The above statement is Excel Vba statement usage is in the debug window
? Xlssheet. UsedRange. Rows. Count
Seemingly VB6.0 by use doesn't support this kind of usage, it is recommended that the annotation this sentence, in other ways for Excel spreadsheet total number and total number of columns,
The available Ado data object implementation,

CodePudding user response:

I can't see you for xlssheet assignment

CodePudding user response:

Actually open the Excel file, using the method of open the database in VB is a common operation method, than using Excel statement is simple to operate, and small error probability, ADO references can be added to the reference, do not need to set up a line one column, ADO object is read one line read, if you want to use the method of ADO object connection, read, modify, delete, etc., can I help you,

CodePudding user response:

Thank you to give me a can give a EXCEL small instance using ADO connection operation? I want to put the EXCEL data stored in the ACCESS database reads the contents inside, there are other better way, please give a instance

CodePudding user response:

I had a test the advice you
 Private Sub Command2_Click () 
Dim As Integer b, c As String
Dim cn As ADODB. Connection
Set the cn=New ADODB. Connection
Cn. The ConnectionString="Provider=Microsoft. ACE. The OLEDB. 12.0; Data Source=e: \ after-sales service quantitative indicators ten-day reports. XLS. Extended Properties='Excel 12.0; HDR=YES '
"Cn. Open
Dim the rs As New ADODB. You
C="SELECT * FROM" & amp; 2015.12 & amp; "
"Rs. The Open c, cn, adOpenStatic, adLockOptimistic "this sentence can't through my sheet name is 2015.12 I assignment of the right way?
'I tried "SELECT * FROM [" & amp; 2015.12 & amp;"] "this also not line, please advise thank you
B=rs. RecordCount
End Sub

CodePudding user response:

In the Set xlsWorkbook=xlsApp. Workbooks. Open (" e: \ after-sales service quantitative indicators ten-day reports. XLS ") statement after add:

The Set xlssheet=xlsWorkbook. Worksheets (1)

On my machine use is right.
  • Related