vba复制一个已经有的Excel文件中的sheet页到一个新建Excel中
DimShAsWorksheetDimWk1AsWorkbookDimWk2AsWorkbookDimiPathAsStringApplication.ScreenUpd...
Dim Sh As Worksheet
Dim Wk1 As Workbook
Dim Wk2 As Workbook
Dim iPath As String
Application.ScreenUpdating = False
Application.DisplayAlerts = FalseiPath = ThisWorkbook.Path & "\"
Set Wk1 = Workbooks.Add
Set Wk2 = Workbooks.Add
Wk1.SaveAs iPath & "NE1" & ".xls"
Wk2.SaveAs iPath & "NE2" & ".xls"
For Each Sh In ThisWorkbook.Worksheets
With Sh
If .Name Like "NE BasicInfo" Then
ThisWorkbook.Sheets("NE BasicInfo").Copy = Workbooks("NE1").Worksheets("sheet2") ' 14
ElseIf .Name Like "Board Info" Then
.Copy before:=Workbooks("NE1").Worksheets("sheet2")
ElseIf .Name Like "Link Info (Non-XPIC)" Then
.Copy before:=Workbooks("NE1").Worksheets("sheet2")
Else: MsgBox "¹¤×÷±í" & .Name & "
End If
End With
Next
****我这个代码是从看网上很多人写的,然后改的,为什么运行到14行的时候,总是报下标越界呢,哪位大神给看看呗,非常感谢!!! 展开
Dim Wk1 As Workbook
Dim Wk2 As Workbook
Dim iPath As String
Application.ScreenUpdating = False
Application.DisplayAlerts = FalseiPath = ThisWorkbook.Path & "\"
Set Wk1 = Workbooks.Add
Set Wk2 = Workbooks.Add
Wk1.SaveAs iPath & "NE1" & ".xls"
Wk2.SaveAs iPath & "NE2" & ".xls"
For Each Sh In ThisWorkbook.Worksheets
With Sh
If .Name Like "NE BasicInfo" Then
ThisWorkbook.Sheets("NE BasicInfo").Copy = Workbooks("NE1").Worksheets("sheet2") ' 14
ElseIf .Name Like "Board Info" Then
.Copy before:=Workbooks("NE1").Worksheets("sheet2")
ElseIf .Name Like "Link Info (Non-XPIC)" Then
.Copy before:=Workbooks("NE1").Worksheets("sheet2")
Else: MsgBox "¹¤×÷±í" & .Name & "
End If
End With
Next
****我这个代码是从看网上很多人写的,然后改的,为什么运行到14行的时候,总是报下标越界呢,哪位大神给看看呗,非常感谢!!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询