VB复制EXCEL表格求助,代码不成功,第一次复制对的,以后都是照片模式
Private Sub CmdExtrOk_Click()Dim excel1 As Excel.Application
Dim excel1book As Excel.Workbook
Dim excel1sheet As Excel.Worksheet
If CombClass.Text = "" Then MsgBox "请选择起始班组!": Exit Sub
If ComMonth.Text = "" Then MsgBox "请选择月份!": Exit Sub
isFileExist = False
Set fs = CreateObject("Scripting.FileSystemObject")
For i = 1 To 4
isFileExist = fs.FileExists(App.Path & "\模块\" & CombClass.Text & "特殊模块\" & ComMonth.Text & ".xls")
Set excel1 = CreateObject("Excel.Application")
excel1.Visible = False
Set excel1book = excel1.Workbooks.Open(App.Path & "\模块\" & CombClass.Text & "特殊模块\" & ComMonth.Text & ".xls")
Set excel1sheet = excel1book.Worksheets("信号")
excel1book.ActiveSheet.UsedRange.Copy
'如果模块i.xls存在,则打开它,打开位置指定获取的是班组按钮的值和月份的值
Set excel1book = Excel.Workbooks.Open(App.Path & "\" & ComMonth.Text & "月份\" & i & "-" & CombClass.Text & ".xls") '打开2.xls
excel1book.Sheets.Add Before:=Worksheets(1) '新建表格
Set excel1sheet = excel1book.Worksheets(1)
excel1sheet.Range("A1").PasteSpecial (xlPasteAll) '粘贴列宽
excel1book.Save
'重新生成excel
'利用mod 4,实现班组名+1,四班循环
CombClass.ListIndex = (CombClass.ListIndex + 1) Mod 4
Next i
excel1.Quit
Set excel1book = Nothing
Set excel1sheet = Nothing
Set excel1 = Nothing
MsgBox ComMonth.Text + "年表工单生成!"
End Sub