我读取数据的代码是:
Dim row As Integer
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.WorksheetSet xlApp = CreateObject("Excel.Application")
Set xlbook = xlApp.Workbooks.Open("C:\ouwei.xls")
Set xlsheet = xlbook.Worksheets(1)
row = 2
Do Text1.Text > "0"
If Text1.Text = xlsheet.Cells(row, 1) Then
Text2.Text = xlsheet.Cells(row, 2)
Text3.Text = xlsheet.Cells(row, 3)
Text4.Text = xlsheet.Cells(row, 4)
Text5.Text = xlsheet.Cells(row, 5)
Text6.Text = xlsheet.Cells(row, 6)
Text7.Text = xlsheet.Cells(row, 7)
Text8.Text = xlsheet.Cells(row, 8)
Text9.Text = xlsheet.Cells(row, 9)
Text10.Text = xlsheet.Cells(row, 10)
End If
row = row + 1
Loop现在我想向这个excel文件添加数据,如果text1=(row,1)则弹出对话框“已有此编号”并不对数据进行操作,如果text1不等于(row,1),则向excel添加数据(判断数据有9行就在第10行添加,有10行就向第11行添加类推,最多添加到第150行),谁能帮忙解决一下,谢谢!
Dim row As Integer
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.WorksheetSet xlApp = CreateObject("Excel.Application")
Set xlbook = xlApp.Workbooks.Open("C:\ouwei.xls")
Set xlsheet = xlbook.Worksheets(1)
row = 2
Do Text1.Text > "0"
If Text1.Text = xlsheet.Cells(row, 1) Then
Text2.Text = xlsheet.Cells(row, 2)
Text3.Text = xlsheet.Cells(row, 3)
Text4.Text = xlsheet.Cells(row, 4)
Text5.Text = xlsheet.Cells(row, 5)
Text6.Text = xlsheet.Cells(row, 6)
Text7.Text = xlsheet.Cells(row, 7)
Text8.Text = xlsheet.Cells(row, 8)
Text9.Text = xlsheet.Cells(row, 9)
Text10.Text = xlsheet.Cells(row, 10)
End If
row = row + 1
Loop现在我想向这个excel文件添加数据,如果text1=(row,1)则弹出对话框“已有此编号”并不对数据进行操作,如果text1不等于(row,1),则向excel添加数据(判断数据有9行就在第10行添加,有10行就向第11行添加类推,最多添加到第150行),谁能帮忙解决一下,谢谢!
解决方案 »
- VB代码对ACCESS数据库压缩和修复问题
- 求VB实现WORD中画表功能的思路或代码(100分)
- 高分请教对很多人来说简单的问题
- 怎样将多个tiff格式的文件合并成一个多页的tiff格式文件?急!!多谢
- 高分求助,我用vb做一个ActiveX控件来操作word对象,请问我如何得到word对象的关闭、保存等事件?
- 请问请用vb6的错误代码表
- 比较菜的问题,但我有难度!!
- ACCESS数据库表中字段为“数字型”,如果其值为NULL时如何处理?
- loadpicture 在装入图片时,屏幕有闪动,怎么可以不让屏幕闪动???
- 请问vb中如何通过编程不重启动并刷新WINDOWS系统图标!
- 请问 Crystal Reports Automation Serve?
- 为什么取出的word表格单元格的内容都有一个“”!
dim flag as boolean
Do while xlsheet.Cells(row+1, 1)<> ""
row = row + 1
If Text1.Text = xlsheet.Cells(row, 1) Then
msgbox “已有此编号”
flag=true
End If
Loopxlsheet.Cells(row+1, 1)="你要添加的内容"
dim flag as boolean
Do while xlsheet.Cells(row+1, 1)<> ""
row = row + 1
If Text1.Text = xlsheet.Cells(row, 1) Then
msgbox “已有此编号”
flag=true
End If
Loopif flag then xlsheet.Cells(row+1, 1)="你要添加的内容"
row = 0
dim flag as boolean
Do while xlsheet.Cells(row+1, 1)<> ""
row = row + 1
If Text1.Text = xlsheet.Cells(row, 1) Then
msgbox “已有此编号”
flag=true
End If
Loopif not flag then xlsheet.Cells(row+1, 1)="你要添加的内容"