如果工作表为空并且不复制任何内容,如何进行循环?

时间:2019-06-24 08:59:14

标签: excel vba

我有一个cvs文件,该文件有时不包含任何数据,我在Excel中提取了该文件,但我想做的循环是:如果工作表“ temp is empty”,我什么也不想复制?

 Sub StartExtract()

 ' Set the sid and client to connect to
   W_System = "P10320"
 ' Run the GUI script
  RunGUIScript
 ' End the GUI session
  objSess.EndTransaction
 'effacer contenu feuille temp
  Sheets("temp").Select
  Cells.Select
  Selection.Delete Shift:=xlUp
 'Switch to the worksheet where the data is loaded to
  Sheets("temp").Select

  'Load the CSV file
  OpenCSVFile

  Sheets("BGSOCIAL").Select
  Columns("B:G").Select
  Selection.ClearContents
  Sheets("temp").Range("B:G").Copy
  Sheets("BGSOCIAL").Range("B:G").PasteSpecial Paste:=xlPasteValues


 Workbooks.Open FileName:="C:\Users\p100789\Documents\SAP\SAP 
 GUI\text.txt"
 Cells.ClearContents
 ActiveWorkbook.Close SaveChanges:=True

 End Sub

1 个答案:

答案 0 :(得分:0)

您可以尝试:

Option Explicit

Sub test()

    With ThisWorkbook.Worksheets("temp")

        If IsEmpty(.UsedRange) Then
            MsgBox "Empty"
        Else

        End If

    End With

End Sub