excel表格中想用vb实现自动提取d:\目录下123.xls文件a1单元格内容到当前b1单元格, 50
2个回答
展开全部
Dim xlsApp As Object
Dim xlsWorkbook As Object
Dim xlssheet As Object
Set xlsApp = CreateObject("Excel.Application")
Set xlsWorkbook = xlsApp.Workbooks.Open(FilePath)
xlsApp.Visible = False
Set xlssheet = xlsWorkbook.Worksheets("Sheet2") '设置活动工作表
Dim iMaxCol As Long, iMaxRow As Long
Dim iCol As Long, iRow As Long
'用这个取数据范围
'iMaxCol = ActiveSheet.UsedRange.Rows.Count
'iMaxRow = ActiveSheet.UsedRange.Columns.Count
iMaxCol = xlssheet.UsedRange.Rows.Count
iMaxRow = xlssheet.UsedRange.Columns.Count
If iMaxCol = 4 Then
MsgBox "文件内容为空,请检查", vbOKOnly
xlsWorkbook.Close (False)
xlsApp.Quit
Set xlssheet = Nothing
Set xlsWorkbook = Nothing
Set xlsApp = Nothing
Exit Sub
End If
For iCol = 5 To iMaxCol
Num = Num + 1
ReDim Preserve SPA(Num)
SPA(Num).SampleIndex = xlssheet.Range("C" & CStr(iCol)).Value
Sta1.Panels(4).Text = "正在读取样品编号为" & SPA(Num).SampleIndex & "的基本数据..."
SPA(Num).ReportNO = xlssheet.Range("D" & CStr(iCol)).Value
SPA(Num).ProductModel = xlssheet.Range("O" & CStr(iCol)).Value & " " & xlssheet.Range("P" & CStr(iCol)).Value
SPA(Num).ENameOfApplicant = xlssheet.Range("F" & CStr(iCol)).Value
SPA(Num).CNameOfApplicant = xlssheet.Range("G" & CStr(iCol)).Value
SPA(Num).AddressOfApplocant = xlssheet.Range("J" & CStr(iCol)).Value
SPA(Num).PhoneOfApplocant = xlssheet.Range("K" & CStr(iCol)).Value
SPA(Num).CodeOfApplocant = xlssheet.Range("L" & CStr(iCol)).Value
SPA(Num).EManufacturer = xlssheet.Range("H" & CStr(iCol)).Value
SPA(Num).CManufacturer = xlssheet.Range("I" & CStr(iCol)).Value
SPA(Num).TireClass = xlssheet.Range("R" & CStr(iCol)).Value
SPA(Num).Comments = xlssheet.Range("AM" & CStr(iCol)).Value
SPA(Num).DateOfTest = xlssheet.Range("AD" & CStr(iCol)).Value
一个例子
追问
太复杂了,看不懂,能否照我的要求写一个,非常感激
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询