VB编写的程序中其中一个窗体代码看不懂,请大神帮帮忙
PrivateSubCommand1_Click(IndexAsInteger)SelectCaseIndexCase0FNDtoMSHCase1DCCase4Unloa...
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
FNDtoMSH
Case 1
DC
Case 4
Unload Me
End Select
End Sub
Sub DC()
Dim ExcelApp As Object
Dim ExcelWorkBook As Object
Dim ExcelWorkSheet As Object
On Error GoTo ErrH
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelWorkBook = ExcelApp.Workbooks.Add
Set ExcelWorkSheet = ExcelWorkBook.Worksheets(1)
ExcelApp.Visible = True
For i = 0 To MSH.Rows - 1
For j = 0 To MSH.Cols - 1
ExcelWorkSheet.cells(i + 1, j + 1) = MSH.TextMatrix(i, j)
Next
Next
Exit Sub
ErrH:
ExcelApp.Quit
Set ExcelApp = Nothing
Set ExcelWorkBook = Nothing
Set ExcelWorkSheet = Nothing
MsgBox Err.Description
End Sub
请大神逐一分析,就是每一段代码注释一下 展开
Select Case Index
Case 0
FNDtoMSH
Case 1
DC
Case 4
Unload Me
End Select
End Sub
Sub DC()
Dim ExcelApp As Object
Dim ExcelWorkBook As Object
Dim ExcelWorkSheet As Object
On Error GoTo ErrH
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelWorkBook = ExcelApp.Workbooks.Add
Set ExcelWorkSheet = ExcelWorkBook.Worksheets(1)
ExcelApp.Visible = True
For i = 0 To MSH.Rows - 1
For j = 0 To MSH.Cols - 1
ExcelWorkSheet.cells(i + 1, j + 1) = MSH.TextMatrix(i, j)
Next
Next
Exit Sub
ErrH:
ExcelApp.Quit
Set ExcelApp = Nothing
Set ExcelWorkBook = Nothing
Set ExcelWorkSheet = Nothing
MsgBox Err.Description
End Sub
请大神逐一分析,就是每一段代码注释一下 展开
展开全部
Private Sub Command1_Click(Index As Integer) 点击操作,输入整形index参数
Select Case Index index不同值对应不同处理方法
Case 0 如果index为0 执行fndtomsh,提供代码里没有这个函数的说明
FNDtoMSH
Case 1 如果index为1,执行dc方法
DC
Case 4 如果index为4,应该是释放窗体,或者关闭窗体之类的操作
Unload Me
End Select
End Sub
Sub DC() dc方法
下面是典型的使用微软office接口操作execel的方法,网上有很多例子
Dim ExcelApp As Object
Dim ExcelWorkBook As Object
Dim ExcelWorkSheet As Object
On Error GoTo ErrH
Set ExcelApp = CreateObject("Excel.Application") ‘创建excel
Set ExcelWorkBook = ExcelApp.Workbooks.Add ’创建exce一个文档book
Set ExcelWorkSheet = ExcelWorkBook.Worksheets(1) ‘创建文档中的一个sheet
ExcelApp.Visible = True ’exce操作为可见
For i = 0 To MSH.Rows - 1 这个msh在方法里没提到,应该是窗体的一个参数
就是两重循环,对设置的每一行的每一列
For j = 0 To MSH.Cols - 1
将指定行的指定列赋值为MSH.TextMatrix对应的i和j
ExcelWorkSheet.cells(i + 1, j + 1) = MSH.TextMatrix(i, j)
Next
Next
Exit Sub
ErrH: 如果发生错误跳转到这里,下面是释放调用的excel资源
ExcelApp.Quit
Set ExcelApp = Nothing
Set ExcelWorkBook = Nothing
Set ExcelWorkSheet = Nothing
MsgBox Err.Description
Select Case Index index不同值对应不同处理方法
Case 0 如果index为0 执行fndtomsh,提供代码里没有这个函数的说明
FNDtoMSH
Case 1 如果index为1,执行dc方法
DC
Case 4 如果index为4,应该是释放窗体,或者关闭窗体之类的操作
Unload Me
End Select
End Sub
Sub DC() dc方法
下面是典型的使用微软office接口操作execel的方法,网上有很多例子
Dim ExcelApp As Object
Dim ExcelWorkBook As Object
Dim ExcelWorkSheet As Object
On Error GoTo ErrH
Set ExcelApp = CreateObject("Excel.Application") ‘创建excel
Set ExcelWorkBook = ExcelApp.Workbooks.Add ’创建exce一个文档book
Set ExcelWorkSheet = ExcelWorkBook.Worksheets(1) ‘创建文档中的一个sheet
ExcelApp.Visible = True ’exce操作为可见
For i = 0 To MSH.Rows - 1 这个msh在方法里没提到,应该是窗体的一个参数
就是两重循环,对设置的每一行的每一列
For j = 0 To MSH.Cols - 1
将指定行的指定列赋值为MSH.TextMatrix对应的i和j
ExcelWorkSheet.cells(i + 1, j + 1) = MSH.TextMatrix(i, j)
Next
Next
Exit Sub
ErrH: 如果发生错误跳转到这里,下面是释放调用的excel资源
ExcelApp.Quit
Set ExcelApp = Nothing
Set ExcelWorkBook = Nothing
Set ExcelWorkSheet = Nothing
MsgBox Err.Description
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询