|
各位网友好
现同一文件夹中有两文件AB,在B中写代码,
代码判断文件A中是否存在工作表C ,代码如何编写,如果把A改为变化的(是一个变量,即文件名称是变化的,但工作表C不变)
请指导,谢谢
- Sub test()
- Application.ScreenUpdating = False
- Dim sht As String, file As String, path As String, wb As Workbook
- sht = "判断结果"
- On Error Resume Next
- Set wsht = ThisWorkbook.Sheets(sht)
- If Err.Number <> 0 Then
- ThisWorkbook.Sheets.Add.Name = sht
- Else
- ThisWorkbook.Sheets(sht).Cells.ClearContents
- Err.Clear
- End If
- path = ThisWorkbook.path
- file = Dir(path & "\*.xls*")
- Do While file <> ""
- i = i + 1
- If file <> ThisWorkbook.Name Then
- Workbooks.Open path & "" & file
- Set wb = ActiveWorkbook
- On Error Resume Next
- Set jude = wb.Sheets("测试")
- If Err <> 0 Then
- ThisWorkbook.Sheets(sht).Cells(i, 1) = file & "工作薄不存在指定工作表!"
- Else
- ThisWorkbook.Sheets(sht).Cells(i, 1) = file & "工作薄存在指定工作表!"
- End If
- Err.Clear
- wb.Close
- Else: ThisWorkbook.Sheets(sht).Cells(1, 1) = "判断结果"
- End If
- file = Dir
- Loop
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|