word对象的释放?

xjbx
博客专家认证
2003-08-06 11:11:12
c/s 方式,批量拆离“word对象”,但没法释放对象,在进程中有很多的“word”。我用set ...=nothing没法实现,导致最后系统资源耗尽。请高手指点,谢谢。

我的代码如下:

On Error Goto errnum
Dim Session As New NotesSession
Dim cdb As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument

'包含对象的RTF 域
Dim item As Variant

' OLE控件句柄
Dim handle As Variant
Dim i As Integer
i=0

'在数据库中查找指定的文档
Set cdb=session.CurrentDatabase
Set view=cdb.GetView("ByTimeFWback")

Set doc = view.GetFirstDocument
While Not(doc Is Nothing)
Forall o In doc.EmbeddedObjects

Set handle=o.Activate(false)
If ( Not handle Is Nothing ) Then
handle.Saveas("d:\doc\"+doc.UniversalID+".doc")
i=i+1

Set handle= Nothing
End If

End Forall
Set doc = view.GetNextDocument(doc)

Wend


Msgbox "共计转换" +Cstr(i)+ "条记录"
errnum:
Msgbox "错误是:"+Error$+"在"+Cstr(Erl())+"行"
...全文
141 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjbx 2003-08-12
  • 打赏
  • 举报
回复
Set handle=o.Activate(false)

说实在的这个handle是个怪异的对象。

因为是(false)方式激活的,所以没办法close。

所以我改用true方式打开,然后close。
poptpeter 2003-08-11
  • 打赏
  • 举报
回复
楼主的这种方式我没试过,不过既然是word对象没释放,可能是循环中激活的word对象没有退出,可以用vba的语句试试,如wordapp.activedocument.close,wordapp.quit之类,但是对于handle我不清楚具体怎么写,看帮助中这么写的

Set object = rtitem.EmbedObject( EMBED_OBJECT, _
"Microsoft Excel Worksheet", "", "Report" )
Set handle = object.Activate ( False )
handle.Application.Cells( 1,1 ).Value = 100
handle.Parent.Save

那么wordapp应该就是handle.Application了。楼主不妨一试,不管成功与否,都请告诉我一声。
xjbx 2003-08-11
  • 打赏
  • 举报
回复
up
rebornman 2003-08-11
  • 打赏
  • 举报
回复
再来一次
xjbx 2003-08-10
  • 打赏
  • 举报
回复
up
rebornman 2003-08-08
  • 打赏
  • 举报
回复
VBA么?
关注~~~!!!
xjbx 2003-08-08
  • 打赏
  • 举报
回复
没别的办法么?
chenyg2000 2003-08-07
  • 打赏
  • 举报
回复
sorry,怪我看得不仔细
laodan 2003-08-06
  • 打赏
  • 举报
回复
楼上的方法事错误的,对于word对象不能使用ExtractFile方法!

可以这样改改

。。。。
Set handle=o.Activate(true)

。。。。
handle.close
chenyg2000 2003-08-06
  • 打赏
  • 举报
回复
可能是这一句的原因 Set handle=o.Activate(false)
参考一下这个例子:

Dim doc As NotesDocument
Dim rtitem As Variant
Dim fileCount As Integer
Const MAX = 100000
fileCount = 0
'...set value of doc...
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) _
And ( o.FileSize > MAX ) Then
fileCount = fileCount + 1
Call o.ExtractFile _
( "c:\reports\newfile" & Cstr(fileCount) )
Call o.Remove
Call doc.Save( True, True )
End If
End Forall
End If
xjbx 2003-08-06
  • 打赏
  • 举报
回复
up

535

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 Exchange Server
社区管理员
  • 消息协作社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧