以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 文件占用 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=172016) |
||||
-- 作者:漂亮美眉vszh -- 发布时间:2021/9/18 10:07:00 -- 文件占用 导出EXCEL报表时 FOX写入数据,同时也调用了VBA对表格做修订 就会一直弹出占用通知 在代码中加入暂停 会稍微好一点 还有什么办法可以完全去除这个报错 一次性批量导出的EXCEL比较多
|
||||
-- 作者:有点蓝 -- 发布时间:2021/9/18 10:21:00 -- 贴出具体代码看看 |
||||
-- 作者:漂亮美眉vszh -- 发布时间:2021/9/18 17:17:00 -- 此主题相关图片如下:111.png ‘’上面是FOX写入报表的代码,多次引用打开关闭MSExcel.Application Book.Save(cy_Ass) \'\'MessageBox.Show(11111) Sleep (5000) Dim App3 As New MSExcel.Application Dim Wb3 As MSExcel.WorkBook = App3.WorkBooks.Open(cy_Ass) Wb3.save() App3.Quit App3.Quit App3.Quit Wb3.dispose App3.dispose Sleep (5000) \'====录入新数据时顺便获取行高,设定行高====== Dim Book2 As New XLS.Book(cy_Ass) Dim SheetSrh As XLS.Sheet = Book2.Sheets("行高控制") \'Dim SheetSrh As XLS.Sheet = Book.Sheets("行高控制") \'Dim SheetSrh1 As XLS.Sheet = Book2.Sheets("行高控制1") \'Dim SheetSrh2 As XLS.Sheet = Book2.Sheets("行高控制2") Names1.Add(15) Names2.add(15) Names3.add(15) Names4.add(15) Dim clnmbh As String = "" ‘‘下面是FOX写入报表代码 |
||||
-- 作者:有点蓝 -- 发布时间:2021/9/18 17:33:00 -- 麻烦贴出完整代码 |
||||
-- 作者:漂亮美眉vszh -- 发布时间:2021/9/18 17:47:00 --
|
||||
-- 作者:有点蓝 -- 发布时间:2021/9/22 8:21:00 -- 1、首先下面红色代码没有任何用处,去掉 Book.Save(cy_Ass) Sleep (2000) If drs.Count > 0 Then Dim App As New MSExcel.Application Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(cy_Ass) wb.save() App.Quit Sleep (2000) Dim Book2 As New XLS.Book(cy_Ass) 2、其次XLS.Book和MSExcel.Application不要交叉混用,并且不要同时打开同一个文件 下面代码红色部分去掉,对应功能外部改为使用vba控制,vba也有合并单元格、删除sheet的用法的:http://www.foxtable.com/webhelp/topics/2121.htm \'MessageBox.Show(300) If drs.Count > 0 Then Dim App31 As New MSExcel.Application Dim Book5 As New XLS.Book(cy_Ass) Dim SheetSrh4 As XLS.Sheet = Book5.Sheets("信息收集") Dim Wb31 As MSExcel.WorkBook = App31.WorkBooks.Open(cy_Ass) Dim Ws As MSExcel.WorkSheet = Wb31.WorkSheets("信息收集") App31.ActiveWindow.view = MSExcel.XlWindowView.xlPageBreakPreview Wb31.save() Sleep (2000) Dim kkki As Integer = 0 For irowH As Integer = 0 To drs.Count + 10 If kkki = 0 Then try If (Ws.HPageBreaks(irowH + 1).Location.Row - 1) < (drs.Count + 8) Then If Names1.Contains(Ws.HPageBreaks(irowH + 1).Location.Row - 1) = False Then Names1.Add(Ws.HPageBreaks(irowH + 1).Location.Row - 1) End If End If catch ex As exception kkki = 1 App31.Quit End try End If Next App31.Quit If drs.Count > 1 Then Names1.Sort For i4 As Integer = 0 To names1.Count - 2 SheetSrh4.MergeCell(names1(i4),0,names1(i4 + 1) - names1(i4),3) Next End If Book5.Save(cy_Ass) End If Dim BookRem As New XLS.Book(cy_Ass) BookRem.Sheets.Remove("行高控制") BookRem.Save(cy_Ass) |
||||
-- 作者:漂亮美眉vszh -- 发布时间:2021/9/22 10:12:00 -- 老师,早上好 通过测试,发现问题基本解决了,非常感谢您。 有个瑕疵 Dim App31 As New MSExcel.Application Dim Wb31 As MSExcel.WorkBook = App31.WorkBooks.Open(cy_Ass) Dim Ws As MSExcel.WorkSheet = Wb31.WorkSheets("信息收集") 就是在前台,能看到打开运行着的表格, 代码运行完毕后,有加入 Wb31.save() Wb31.Close App31.Quit 能否在运行过程中,在后台打开表格,不要让用户在前台看着表格打开呢? |
||||
-- 作者:有点蓝 -- 发布时间:2021/9/22 10:30:00 -- Dim App31 As New MSExcel.Application App31.Visible = false
|