我有一個宏編寫從一個工作簿中選取的工作表,並將其複製到另一個工作簿,並以新名稱保存它。我需要反覆運行相同的查詢,直到我創建了大約6個單獨的文件。每個宏都可以工作,我可以一次一個地調用它們,但它們不會按順序運行。我相信我知道問題出在這樣一個事實,即我編寫的代碼不會再引用源代碼工作簿,而且我也不知道如何編寫代碼來完成它。運行多個宏來創建單獨的工作簿
附加的代碼是我正在使用的,它可能看起來有點草率 - 我把幾個不同的宏組合在一起,讓這個工作。 Gqp Master是所有其他工作簿正在創建的主工作簿的名稱。
Sub Snuth()
'This will prevent the alet from popping up when overwriting graphs, etc
Application.DisplayAlerts = False
Dim FName As String
Dim FPath As String
Dim NewBook As Workbook
Dim strFileName As String
Dim WS As Worksheet
Dim WBk As Workbook
Set WBk = ("Gap Master")
For Each WS In Worksheets
WS.Visible = True
Next
For Each WS In Worksheets
If WS.Range("C4") <> "Snuth, John" Then
WS.Visible = False
End If
If WS.Range("C4") = "Snuth, John" Then
WS.Visible = True
End If
Next WS
FPath = "C:\Users\mmarshall\Documents\GAP\GAP Development"
FName = "Snuth GAP " & Format(Date, "yyyy-mm-dd") & ".xlsx"
Set NewBook = Workbooks.Add
ThisWorkbook.Sheets.Copy Before:=NewBook.Sheets(1)
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
ActiveWindow.SelectedSheets.Delete
If Dir(FPath & "\" & FName) <> "" Then
MsgBox "File " & FPath & "\" & FName & " already exists"
Else
NewBook.SaveAs Filename:=FPath & "\" & FName
End If
Application.DisplayAlerts = True
End Sub
因此,你有其他的宏是類似於這個,需要依次調用? –