如果您想將工作表從工作簿移動(或複製)到另一個工作表,您必須將其他工作簿設置爲var。我給大家舉一個例子:
Dim oNewWB as Workbook
Dim oCurWB as Workbook
'Store active workbook in a var
Set oCurWB = ActiveWorkbook
'Open a new workbook
Set oNewWB = Application.Workbooks.Open(<pathToWorkbookHere>)
'Move "Sheet1" from the current workbook to new one
oCurWB.Sheets("Sheet1").Move After:=oNewWB.Sheets(oNewWB.Sheets.Count)
[編輯] Maverik
所建議的新的代碼塊 比方說,你想在您的工作簿複製每表到新:
Dim oNewWB as Workbook
Dim oCurWB as Workbook
Dim Sheet as Worksheet
'Store active workbook in a var
Set oCurWB = ActiveWorkbook
'Open a new workbook
Set oNewWB = Application.Workbooks.Open(<pathToWorkbookHere>)
For Each Sheet In oCurWB.Sheets
'Move "Sheet1" from the current workbook to new one
Sheet.Move After:=oNewWB.Sheets(oNewWB.Sheets.Count)
Next Sheet
HTH
我認爲OP希望將每個表單寫入一個文件中,並且可能爲代碼添加一個For Each字節將使它完美(也許作爲一個單獨的位,以便覆蓋這兩種情況) – Maverik
@Maverik:謝謝你的建議:)它已完成 – JMax
快樂! +1爲完美的解決方案,其他絆腳者可以使用,無論他們在尋找哪種模式 – Maverik