
[![匯出時我希望忽略黃色的工作表,Ws.rows 命令刪除前 10 行,但 vba 腳本仍然將所有工作表匯出為 CSV,這是我不想要的,所有工作表都有資料。我附上了電子表格,第一頁是索引,在底部你會看到表格,accom Price Overnight。
Sub ExportCSV()
Application.DisplayAlerts = False
ActiveWorkbook.Save
Dim ws As Worksheet
Dim path As String
path = ActiveWorkbook.path & "\" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
For Each ws In ActiveWorkbook.Worksheets
ws.Rows("1:10").Delete
If ws.Name <> "Document Control" And ws.Name <> "Index sheet" Then
'With ws
ws.SaveAs filename:=path & "_" & ws.Name & ".csv", FileFormat:=xlCSV, CreateBackup:=False
'End With
End If
Next ws
Application.DisplayAlerts = True
End Sub
答案1
您不能僅儲存工作表的一部分。匯出前需要刪除不需要的範圍。
由於保存了原始工作簿,因此您不會丟失資料。
ws.Rows("1:10").Delete