vb 操作EXCE第一次运行可以,第二次运行出错
Private Sub Command1_Click()
Dim ex As excel.Application
Dim wb As excel.Workbook
Dim sh As Object
CommonDialog1.ShowOpen
Set ex = CreateObject("Excel.Application")
Set wb = ex.Workbooks.Open(CommonDialog1.FileName)
Dim a As Integer
Dim k As Integer
a = 1
For k = 1 To 3
a = a + 1
wb.Sheets(1).Select
wb.Sheets(1).Copy Before:=Sheets(a) Next k '这行出错
Set sh = Nothing
wb.Close savechanges:=True
ex.Quit
Set wb = Nothing
Set ex = Nothing
MsgBox "ok"
End Sub
有办法解结吗?
[最优解释]
要明确指定在同一个工作簿中进行复制
wb.Sheets(1).Copy Before:=wb.Sheets(a)