以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 请问循环打开多个word文档复制内容时,如何重用对象?而不是new一大堆application出来,不断创建和回收内存 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=177427) |
-- 作者:chen37280600 -- 发布时间:2022/5/21 17:45:00 -- 请问循环打开多个word文档复制内容时,如何重用对象?而不是new一大堆application出来,不断创建和回收内存 Dim dlg As New OpenFileDialog dlg.Filter = "Word文件|*.doc;*.docx" dlg.MultiSelect = True If dlg.ShowDialog =DialogResult.OK Then If dlg.FileNames.Count > 0 Then Dim app As New MSWord.Application Try For Each fl As String In dlg.FileNames Dim doc = app.Documents.Open(fl) app.Selection.WholeStory() app.Selection.Copy() app.Close Next Catch ex As exception MessageBox.Show(ex.message) Finally app.Quit End Try MessageBox.Show(1) End If End If
[此贴子已经被作者于2022/5/21 17:46:01编辑过]
|
-- 作者:chen37280600 -- 发布时间:2022/5/21 22:18:00 -- 没事了,我自己解决了 Dim dlg As New OpenFileDialog dlg.Filter = "Word文件|*.doc;*.docx" dlg.MultiSelect = True If dlg.ShowDialog =DialogResult.OK Then If dlg.FileNames.Count > 0 Then Dim app As New MSWord.Application Try For Each fl As String In dlg.FileNames Dim doc = app.Documents.Open(fl) app.Selection.WholeStory() app.Selection.Copy() doc.Close Next Catch ex As exception MessageBox.Show(ex.message) Finally app.Quit End Try MessageBox.Show(1) End If End If [此贴子已经被作者于2022/5/22 10:01:17编辑过]
|