以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助] 复制出错 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=187019) |
-- 作者:leoli -- 发布时间:2023/6/15 12:47:00 -- [求助] 复制出错 老师, 以下复制出错,要把Data1 中sheet1 复制到 Data2 中sheet1 ,谢谢。 Dim path1 As String = "C:\\Users\\Desktop\\改善项目\\Project\\Attachments\\Data1.xlsx" Dim path2 As String = "C:\\Users\\Desktop\\改善项目\\Project\\Attachments\\Data2.xlsx" Dim app As New MSExcel.Application Dim wb1 As MSExcel.WorkBook = app.WorkBooks.Open(path1) Dim wb2 As MSExcel.WorkBook = app.WorkBooks.Open(path2) wb2.Sheets(2).Copy(After:=wb1.WorkSheets.Item(wb1.WorkSheets.Count)) wb1.Save App.Quit |
-- 作者:有点蓝 -- 发布时间:2023/6/15 13:35:00 -- 2个文件发上来测试一下 |
-- 作者:leoli -- 发布时间:2023/6/15 13:57:00 -- [此贴子已经被作者于2023/6/15 13:57:12编辑过]
|
-- 作者:有点蓝 -- 发布时间:2023/6/15 14:33:00 -- wb2.Sheets(2).Copy(After:=wb1.Sheets(wb1.Sheets.Count)) |
-- 作者:leoli -- 发布时间:2023/6/21 16:28:00 -- 老师,改成这样,还是出错,如下: Dim path1 As String = "C:\\Users\\wj1087\\Desktop\\改善项目\\Project\\Attachments\\Data1.xlsx" Dim path2 As String = "C:\\Users\\wj1087\\Desktop\\改善项目\\Project\\Attachments\\Data2.xlsx" Dim app As New MSExcel.Application Dim wb1 As MSExcel.WorkBook = app.WorkBooks.Open(path1) Dim wb2 As MSExcel.WorkBook = app.WorkBooks.Open(path2) wb2.Sheets(2).Copy(After:=wb1.Sheets(wb1.Sheets.Count)) wb1.Save App.Quit |
-- 作者:有点蓝 -- 发布时间:2023/6/21 16:34:00 -- 可能wb2只有一个sheet 重启电脑再试试。或者每次测试有看看有没有execl进程,关闭掉再做下一次测试 Dim path1 As String = "C:\\Users\\wj1087\\Desktop\\改善项目\\Project\\Attachments\\Data1.xlsx" Dim path2 As String = "C:\\Users\\wj1087\\Desktop\\改善项目\\Project\\Attachments\\Data2.xlsx" Dim app As New MSExcel.Application try Dim wb1 As MSExcel.WorkBook = app.WorkBooks.Open(path1) Dim wb2 As MSExcel.WorkBook = app.WorkBooks.Open(path2) wb2.Sheets(2).Copy(After:=wb1.Sheets(wb1.Sheets.Count)) wb1.Save wb1.close wb2.close App.Quit catch ex as exception App.Quit msgbox(ex.message) end try
|