如何创建可执行以下操作的宏:
我得到运行时错误424,在调试时,突出显示的行是
Sheet11.Range("A6:HF10000").Select
Sub Copy2RangesNewWorkbook()
'
' Copy2RangesNewWorkbook Macro
'
Dim pvt_wbk_New As Excel.Workbook
Dim pvt_xls_Current As Excel.Worksheet
With pvt_xls_Current
ActiveSheet.Range("A2:AT10000").Select
Selection.Copy
End With
Set pvt_wbk_New = Application.Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With pvt_xls_Current
Sheet11.Range("A6:HF10000").Select
Selection.Copy
End With
With pvt_wbk_New
Sheets.Add After:=Sheets(Sheets.Count)
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End With
End Sub
答案 0 :(得分:1)
尝试:
Sub Copy2RangesNewWorkbook()
Dim pvt_wb_New As Excel.Workbook
Dim pvt_ws_NewTarget1 As Worksheet
Dim pvt_ws_NewTarget2 As Worksheet
Dim pvt_ws_Current As Worksheet
Dim pvt_wb_Current As Workbook
Set pvt_ws_Current = ActiveSheet
Set pvt_wb_Current = ActiveWorkbook
Set pvt_wb_New = Application.Workbooks.Add
Set pvt_ws_NewTarget1 = pvt_wb_New.Sheets(1)
Set pvt_ws_NewTarget2 = pvt_wb_New.Worksheets.Add
pvt_ws_Current.Range("A2:AT10000").Copy
pvt_ws_NewTarget1.Range("A2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
pvt_wb_Current.Sheets("Sheet11").Range("A6:HF10000").Copy
pvt_ws_NewTarget2.Range("A6").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub