帮忙改一段VB+excel的代码
现在有如下程序,运行到最后一个GET的地方报错,应该是循环提取EXCEL导致的出了问题,希望大家给改改,还有如果想要每次都把结果写到一个.TXT里去,而且结果不替换,而是用>1.....>2....>3...这样分开,代码应该怎么改????谢谢大家~~~~~~
Private Sub Command1_Click()
Dim TargetFileLength, StartLength As Long
'目标文件长度及在源文件中的开始长度
Dim SourceFileName, TargetFileName As String
'源文件全路径名和目标文件全路径名
Dim ReadPos, WritePos As Long '读写位置
Dim DSX() As Byte
'为字节数组,用来存储读写内容
Dim ReadFileNo, WriteFileNo As Integer
'读写文件号
Dim xlExcel As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim AppExcel As Object
Dim i As Integer
Const Unit = 100000
'读写块的大小
SourceFileName = InputBox("输入源文件名")
TargetFileName = InputBox("输入目标文件名")
ReadFileNo = FreeFile
Open SourceFileName For Binary Access Read As ReadFileNo
'打开欲截取的源文件名
WriteFileNo = FreeFile
Open TargetFileName For Binary Access Write As WriteFileNo
'欲打开的目标文件名
'以下变量与EXCEL相关
Set xlExcel = CreateObject("Excel.Application")
xlExcel.Workbooks.Open "d:\m.xls" '文件路径
Set xlBook = xlExcel.Workbooks("m.xls")
Set xlSheet = xlBook.Worksheets(1)
For i = 2 To 1000
If xlSheet.Cells(i, 2).Value <> "" Then
StartLength = xlSheet.Cells(i, 2).Value - 1
'此值也可以通过其它方式获取
TargetFileLength = xlSheet.Cells(i, 3).Value
'1)同上;
'2)或由目标文件在源文件中的结束长度转换而来;
'3)该值在读写过程中是个变数
ReadPos = 1: WritePos = 1
ReadPos = ReadPos + StartLength
'给读写位置赋初值
'以下部分读出写入读写块的整数部分
ReDim DSX(Unit) As Byte
'设置存储字节数组的大小
Do While TargetFileLength > Unit
'TargetFileLength为变数,反映读写过程中还剩的字节数
Get #ReadFileNo, ReadPos, DSX()
Put #WriteFileNo, WritePos, DSX()
ReadPos = ReadPos + Unit
WritePos = WritePos + Unit
TargetFileLength = TargetFileLength - Unit
Loop
'以下读写除读写块倍数后的剩余部分
ReDim DSX(TargetFileLength) As Byte
Get #ReadFileNo, ReadPos, DSX()
Put #WriteFileNo, WritePos, DSX()
Close WriteFileNo, ReadFileNo
End If
Next i
Application.DisplayAlerts = False
xlExcel.Quit '退出excel
End Sub
运行的时候倒数第一个get那里的命令出问题了,现在我在改,希望循环调用excel的参数,然后把结果按照一次一次结果编号放在一个文本里,有什么要改进的希望大家提意见