下面是我在vb中编的代码,我想在打开第二个表之前判断这个表是否存在,如果存在则继续运行,不存在则退出整个程序,请各位帮一下忙,谢谢!
Private Sub a_Click()
Dim xlApp As Excel.Application '定义EXCEL类
Dim xlBook As Excel.Workbook '定义工件簿类
Dim xlsheet As Excel.Worksheet '定义工作表类
Dim xlChart As Excel.Chart
Dim xlrange As Excel.Range
Dim i, j As Integer
i = 0
j = 3
Dim xllegend As Boolean
Dim xlct As String
Dim xlvt As String
Text1.Text = form1.Text2.Text
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = False '设置EXCEL可见
Set xlBook = xlApp.Workbooks.Open(App.Path & Text1.Text) '打开EXCEL工作簿
Set xlsheet = xlBook.Sheets("sheet1")
xlsheet.Activate
With xlsheet
If .Range(.Cells(1, 1), .Cells(1, 5)).Font.Name = "黑体" Then
If .Range(.Cells(1, 1), .Cells(1, 5)).Font.Size = "14" Then
If .Range(.Cells(1, 1), .Cells(1, 5)).Font.ColorIndex = 5 Then
If .Range(.Cells(1, 1), .Cells(1, 5)).HorizontalAlignment = xlCenter Then
If .Range(.Cells(1, 1), .Cells(1, 5)).VerticalAlignment = xlCenter Then
i = i + 2
End If
End If
End If
End If
End If
If .Range(.Cells(1, 1), .Cells(1, 5)).RowHeight = 20 Then
i = i + 1
End If
For j = 3 To 40
If j = 15 Then
j = 16
End If
If j = 28 Then
j = 29
End If
If j <> 15 Then
If j <> 28 Then
If .Range(.Cells(j, 6), .Cells(j, 6)).Value = .Cells(j, 4).Value * .Cells(j, 5).Value Then
j = j + 1
End If
End If
End If
Next
If j = 41 Then
i = i + 2
End If
If .Range("A2:F2").Font.Name = "宋体" Then
If .Range("A2:F2").Font.Size = "12" Then
If .Range("A2:F2").Font.Bold = True Then
If .Range("A2:F2").HorizontalAlignment = xlCenter Then
If .Range("A2:F2").Borders(xlInsideVertical).Weight = xlThin Then
' ####到最适合列宽
i = i + 2
End If
End If
End If
End If
End If
If .Range(.Cells(1, 1), .Cells(38, 6)).Copy Then
If .Range(.Cells(1, 1), .Cells(38, 6)).PasteSpecial = True Then
i = i + 1
End If
End If
End With
Set xlsheet = xlBook.Sheets("销售情况汇总")