大家给我看看这程序什么问题
Public Function PathBe() As Boolean
Dim path As String
If Dir(mvarPath, vbDirectory) = "" Then//运行时说这里对象未初始化
MessageBox.Show("该项目的图纸保存路径" & mvarPath & "不存在,是否创建一个?", "", MessageBoxButtons.YesNo)
If MessageBox.Show("该项目的图纸保存路径" & mvarPath & "不存在,是否创建一个?", "", MessageBoxButtons.YesNo) Then
'path = Split(mvarPath, "\")
'On Error GoTo endmkdir
'While path(i) <> ""
On Error Resume Next
MkDir(mvarPath)
If Err.Number <> 0 Then
MsgBox("程序不能创建该文件夹,请手动创建或另选一个文件夹.")
PathBe = False
Err.Clear()
Else
'Wend
'MkDir "d:\a\\b"
PathBe = True
End If
Else
PathBe = False
End If
Else
PathBe = True
End If
End Function
Public Function DrawYdsbqd() As Boolean
Dim i, j, k As Integer
Dim tablePaper As Integer '图纸张数
Dim PaperID As Integer
Dim AppExcel As New Excel.Application
Dim aWorkbook As Excel.Workbook
Dim templetopened As Boolean
Dim DrawingNum As Integer
Dim rownum As Integer 'Excel表行号
Dim mvarDrawingNum As Integer
tablePaper = CInt((mvarDrawingNum + 29) / 30)
'测试 Microsoft Excel 的副本是否在运行。
For i = 1 To tablePaper
On Error Resume Next '延迟错误捕获。
'不带第一个参数调用 Getobject 函数将返回对该应用程序的实例的引用。如果该应用程序不在运行,则会产生错误。
AppExcel = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
AppExcel = CreateObject("Excel.Application")
Err.Clear() '如果发生错误则要清除 Err 对象。
End If
AppExcel.Visible = True
With AppExcel
For Each aWorkbook In .Workbooks
aWorkbook.Activate()
If aWorkbook.FullName = Application.StartupPath & mvarPath & "\用电设备清单" & i & ".xls" Then
aWorkbook.Close()
Else
If aWorkbook.FullName = Application.StartupPath & "\Ledr\L_XLS\用电设备清单.xls" Then
templetopened = True
'GoTo EndsearchTemp
End If
End If
Next aWorkbook
If templetopened = False Then AppExcel.Workbooks.Open(Application.StartupPath & "\Ledr\L_XLS\用电设备清单.xls")
EndsearchTemp:
On Error GoTo ExitFun
.ActiveWorkbook.SaveAs(Application.StartupPath & mvarPath & "\用电设备清单" & i & ".xls")
End With
'对文件进行操作。
rownum = 7
With AppExcel.ActiveWorkbook.Worksheets(1)
.Range("designer").Value = gcsz.DYCOM_Designed_by
.Range("Proofer").Value = gcsz.DYCOM_Checked_by
.Range("Auditer").Value = gcsz.DYCOM_Verified_by
.Range("ProjectCode").Value = gcsz.DYCOM_Project_Code
.Range("ProjectName").Value = gcsz.DYCOM_Project_Name
.Range("ItemCode").Value = gcsz.DYCOM_Item_Code
.Range("ItemName").Value = gcsz.DYCOM_Item_Name
For j = 1 To MDImain.AxVSFlexGrid2.Rows
If MDImain.AxVSFlexGrid2.get_TextMatrix(j, 1) <> "" Then
.Cells(rownum, 1).Value() = rownum - 6
.Cells(rownum, 2).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 1)
.Cells(rownum, 3).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 2)
.Cells(rownum, 4).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 3)
.Cells(rownum, 5).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 4)
.Cells(rownum, 6).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 5)
.Cells(rownum, 7).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 6)
.Cells(rownum, 8).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 7)
.Cells(rownum, 9).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 8)
.Cells(rownum, 10).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 9)
' .Cells(rownum, 11).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 10)
' .Cells(rownum, 12).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 10)
.Cells(rownum, 13).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 11)
.Cells(rownum, 14).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 12)
.Cells(rownum, 15).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 13)
.Cells(rownum, 16).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 14)
' .Cells(rownum, 17).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 15)
'.Cells(rownum, 18).Value() = MDImain.AxVSFlexGrid2.get_TextMatrix(j, 16)
rownum = rownum + 1
End If
Next j
End With
Next i
AppExcel.ActiveWorkbook.Save()
'释放对该应用程序
AppExcel = Nothing
aWorkbook = Nothing
MessageBox.Show("图纸目录填写完成!保存于:" & ThisPrj.path & "目录中!")
Exit Function
'当用户取消
ExitFun:
With AppExcel
For Each aWorkbook In .Workbooks
aWorkbook.Activate()
If aWorkbook.FullName = Application.StartupPath & "\Ledr\L_XLS\用电设备清单.xls" Then
aWorkbook.Close()
End If
Next
End With
AppExcel = Nothing
aWorkbook = Nothing
' MessageBox.Show("取消生成用电设备清单.")
End Function
牛人帮我把这个程序调试好