VB读取EXCEL 单元格内的内容,下面代码是读取 excel 中sheet1内单元格的值,如何让他读取 excel 中sheet2
PrivateSubCommand1_Click()Dima(101)AsStringDimiAsIntegerDimbAsDoubleDimxlAppAsExcel.A...
Private Sub Command1_Click()
Dim a(101) As String
Dim i As Integer
Dim b As Double
Dim xlApp As Excel.Application
Dim xllBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelworkBook = ExcelApp.Workbooks.Open("D:\my.xls")
ExcelApp.Visible = False
ExcelApp.Range("A1").Select
'读取值
Text1.Text = ExcelApp.ActiveCell.Offset(0, 0).Value
Text2.Text = ExcelApp.ActiveCell.Offset(0, 1).Value
Text3.Text = ExcelApp.ActiveCell.Offset(1, 2).Value
Set ExcelSheet = Nothing
Set ExcelBook = Nothing
Set ExcelApp = Nothing
End Sub 展开
Dim a(101) As String
Dim i As Integer
Dim b As Double
Dim xlApp As Excel.Application
Dim xllBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelworkBook = ExcelApp.Workbooks.Open("D:\my.xls")
ExcelApp.Visible = False
ExcelApp.Range("A1").Select
'读取值
Text1.Text = ExcelApp.ActiveCell.Offset(0, 0).Value
Text2.Text = ExcelApp.ActiveCell.Offset(0, 1).Value
Text3.Text = ExcelApp.ActiveCell.Offset(1, 2).Value
Set ExcelSheet = Nothing
Set ExcelBook = Nothing
Set ExcelApp = Nothing
End Sub 展开
1个回答
展开全部
错误不少啊?
用这个吧!
Dim a(101) As String
Dim i As Integer
Dim b As Double
Dim ExcelApp As Excel.Application
Dim ExcelworkBook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelworkBook = ExcelApp.Workbooks.Open("C:\Book1.xls")
ExcelApp.Visible = False
ExcelworkBook.Sheets("Sheet2").Activate
ExcelApp.Range("A1").Select
'读取值
Text1.Text = ExcelApp.ActiveCell.Offset(0, 0).Value
Text2.Text = ExcelApp.ActiveCell.Offset(0, 1).Value
Text3.Text = ExcelApp.ActiveCell.Offset(1, 2).Value
ExcelworkBook.Close
Set ExcelSheet = Nothing
Set ExcelworkBook = Nothing
Set ExcelApp = Nothing
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询