word automation vb.net [英] word automation vb.net

查看:57
本文介绍了word automation vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在构建一个应用程序,它将文本文件中的字段与

a字模板合并,将生成的word文件保存到用户的硬盘中,

然后通过电子邮件将文件作为附件发送。


我遇到的问题是我无法删除我在

由于文件被电子邮件进程锁定而导致进程结束。由于病毒检查,
似乎比完成代码需要的时间更长

软件在发布之前拦截邮件(至少那是什么

我把它缩小到了。)


我不想在代码完成后留下文件。而且我不想我想要阻止完成代码流程,直到发送

电子邮件,以防电子邮件进程在某些机器上花费的时间超过

其他人。


我不确定是否有更好的方法来处理代码中的附件

so我没有必要将文件保存到用户的桌面。或者,如果我可以使用

deattach进程,我可以从代码触发,以便稍后删除该文件。或者

别的东西。


我附上了以下代码的片段:


谢谢

Steve


------------


WordDoc.SaveAs(sSaveFileName)

做的不是WordDoc.Saved

Application.DoEvents()

循环

WordDoc.Close(Word。 WdSaveOptions.wdDoNotSaveChange s)


''通过电子邮件发送已保存的合并文档。


Dim Fromaddress As New MailAddress(fromaddress)

Dim Toaddress As New MailAddress(" toaddress")

Dim myMail As New MailMessage(Fromaddress,ToAddress)

myMail.Subject =" test" ;

Dim AttachmentFile As Attachment = New Attachment(sSaveFileName)

myMail.Attachments.Add(AttachmentFile)

myMail.Priority = MailPriority.High

Dim client As New SmtpClient

client.Host =" hostaddress"

client.Send(myMail)

>
''发布参考文献。


WordMailMerge =没什么

WordDoc =没什么

WordApp =没什么


''删除临时文件。


System.IO.File.Delete(sSaveFileName)

解决方案

抱歉,它就像Word Automation一样简单


但当然;微软不再支持vb6了,所以你大吼大叫

的好运


我会建立一台时间机器,然后回到90年代从不打扰

用VB.NOT


-Susie,DBA


史蒂夫写道:
< blockquote class =post_quotes>
我一直在构建一个应用程序,它将文本文件中的字段与

a字模板合并,将生成的word文件保存到用户'' s硬盘,

然后通过电子邮件将文件作为附件发送。


我遇到的问题是我不能删除这个词文件由于文件被电子邮件进程锁定而保存在进程结束的

。由于病毒检查,
似乎比完成代码需要的时间更长

软件在发布之前拦截邮件(至少那是什么

我把它缩小到了。)


我不想在代码完成后留下文件。而且我不想我想要阻止完成代码流程,直到发送

电子邮件,以防电子邮件进程在某些机器上花费的时间超过

其他人。


我不确定是否有更好的方法来处理代码中的附件

so我没有必要将文件保存到用户的桌面。或者,如果我可以使用

deattach进程,我可以从代码触发,以便稍后删除该文件。或者

别的东西。


我附上了以下代码的片段:


谢谢

Steve


------------


WordDoc.SaveAs(sSaveFileName)

做的不是WordDoc.Saved

Application.DoEvents()

循环

WordDoc.Close(Word。 WdSaveOptions.wdDoNotSaveChange s)


''通过电子邮件发送已保存的合并文档。


Dim Fromaddress As New MailAddress(fromaddress)

Dim Toaddress As New MailAddress(" toaddress")

Dim myMail As New MailMessage(Fromaddress,ToAddress)

myMail.Subject =" test" ;

Dim AttachmentFile As Attachment = New Attachment(sSaveFileName)

myMail.Attachments.Add(AttachmentFile)

myMail.Priority = MailPriority.High

Dim client As New SmtpClient

client.Host =" hostaddress"

client.Send(myMail)

>
''发布参考文献。


WordMailMerge =没什么

WordDoc =没什么

WordApp = Nothing


''删除临时文件。


System.IO.File.Delete(sSaveFileName)


无视Susie,他/她/它遭受分裂的个性而且没有一个他们是真正的程序员......


我想你想看一下SmtpClient.SendCompleted文档,

这就是你所缺少的。


< blockquote>你的WordDoc.Close后你需要一个WordDoc.Quit。

_________________________________

死神


史蒂夫 < s。***** @ comcast.netwrote in message

news:eO ************** @ TK2MSFTNGP03.phx.gbl ...


我一直在构建一个应用程序,它将合并文本文件中的字段

with

a word template ,将生成的word文件保存到用户的硬

驱动器,

,然后通过电子邮件将文件作为附件发送。


我遇到的问题是,由于文件被电子邮件进程锁定,我无法删除我在过程结束时保存的单词文件。它因为病毒而需要的时间比代码需要更长的时间才能完成

检查

软件在发布之前拦截邮件(至少那是什么

什么

我把它缩小到了。)


我不想代码完成后留下文件。而我

我认为我不想完成代码流程,直到发送

电子邮件,以防电子邮件进程在某些机器上花费更长时间



其他。


我不确定是否有更好的方法来处理代码中的附件

所以我没有必要将文件保存到用户的桌面。或者,如果我可以使用

deattach进程,我可以从代码中触发以后删除文件。



其他东西。


我附上了以下代码片段:


谢谢

Steve


------------


WordDoc.SaveAs(sSaveFileName)

请勿使用WordDoc.Saved

Application.DoEvents()

循环

WordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChange s)


''通过电子邮件发送已保存的合并文档。

Dim Fromaddress As New MailAddress(fromaddress)

Dim Toaddress As New MailAddress(" toaddress")

Dim myMail As New MailMessage(Fromaddress,ToAddress)

myMail.Subject =" test"

Dim AttachmentFile As Attachment =新附件(sSaveFileName)

myMail.Attachments.Add(AttachmentFile)

myMail.Priority = MailPriority.High

昏暗客户端作为新的SmtpClient

client.Host =" hostaddress"

client.Send(myMail)


''发布参考文献。


WordMailMerge =没什么

WordDoc =没什么

WordApp =没什么


''删除临时文件。

System.IO.File.Delete(sSaveFileName)



I''ve been building an application that will merge fields in a text file with
a word template, save the resulting word file out to the user''s hard drive,
and then email the file as an attachment.

The problem I''m having is that I can''t delete the word file I saved at the
end of the process due to the file being locked by the email process. It
appears to take longer than the code takes to complete due to virus checking
software that intercepts the mail before releasing it (at least that''s what
I''ve narrowed it down to).

I don''t want to leave the file around after the code has completed. And I
don''t think I want to hold up the completion of the code process until the
email gets sent in case the email process takes longer on some machines than
others.

I''m not sure if there is a better way to handle the attachment in the code
so I don''t have to save a file to the user''s desktop. Or if I can use a
deattach process that I can trigger from code to delete the file later. Or
something else.

I''ve attached a snippet of the code below:

Thanks
Steve

------------

WordDoc.SaveAs(sSaveFileName)
Do While Not WordDoc.Saved
Application.DoEvents()
Loop
WordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChange s)

'' Email the Saved Merge Document.

Dim Fromaddress As New MailAddress("fromaddress")
Dim Toaddress As New MailAddress("toaddress")
Dim myMail As New MailMessage(Fromaddress, ToAddress)
myMail.Subject = "test"
Dim AttachmentFile As Attachment = New Attachment(sSaveFileName)
myMail.Attachments.Add(AttachmentFile)
myMail.Priority = MailPriority.High
Dim client As New SmtpClient
client.Host = "hostaddress"
client.Send(myMail)

'' Release the references.

WordMailMerge = Nothing
WordDoc = Nothing
WordApp = Nothing

'' Delete the temporary files.

System.IO.File.Delete(sSaveFileName)


解决方案

sorry bud it is as simple as Word Automation

but of course; Microsoft doesn''t support vb6 anymore so you''re shit out
of luck

I would build a time machine and go back to the 90s and never bother
with VB.NOT

-Susie, DBA

Steve wrote:

I''ve been building an application that will merge fields in a text file with
a word template, save the resulting word file out to the user''s hard drive,
and then email the file as an attachment.

The problem I''m having is that I can''t delete the word file I saved at the
end of the process due to the file being locked by the email process. It
appears to take longer than the code takes to complete due to virus checking
software that intercepts the mail before releasing it (at least that''s what
I''ve narrowed it down to).

I don''t want to leave the file around after the code has completed. And I
don''t think I want to hold up the completion of the code process until the
email gets sent in case the email process takes longer on some machines than
others.

I''m not sure if there is a better way to handle the attachment in the code
so I don''t have to save a file to the user''s desktop. Or if I can use a
deattach process that I can trigger from code to delete the file later. Or
something else.

I''ve attached a snippet of the code below:

Thanks
Steve

------------

WordDoc.SaveAs(sSaveFileName)
Do While Not WordDoc.Saved
Application.DoEvents()
Loop
WordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChange s)

'' Email the Saved Merge Document.

Dim Fromaddress As New MailAddress("fromaddress")
Dim Toaddress As New MailAddress("toaddress")
Dim myMail As New MailMessage(Fromaddress, ToAddress)
myMail.Subject = "test"
Dim AttachmentFile As Attachment = New Attachment(sSaveFileName)
myMail.Attachments.Add(AttachmentFile)
myMail.Priority = MailPriority.High
Dim client As New SmtpClient
client.Host = "hostaddress"
client.Send(myMail)

'' Release the references.

WordMailMerge = Nothing
WordDoc = Nothing
WordApp = Nothing

'' Delete the temporary files.

System.IO.File.Delete(sSaveFileName)


Disregard "Susie", he/she/it suffers from split personalities and none
of them are real programmers....

I think you want to look at the SmtpClient.SendCompleted documentation,
that''s what you are missing.


You need a WordDoc.Quit after your WordDoc.Close.
_________________________________
The Grim Reaper

"Steve" <s.*****@comcast.netwrote in message
news:eO**************@TK2MSFTNGP03.phx.gbl...

I''ve been building an application that will merge fields in a text file
with
a word template, save the resulting word file out to the user''s hard
drive,
and then email the file as an attachment.

The problem I''m having is that I can''t delete the word file I saved at the
end of the process due to the file being locked by the email process. It
appears to take longer than the code takes to complete due to virus
checking
software that intercepts the mail before releasing it (at least that''s
what
I''ve narrowed it down to).

I don''t want to leave the file around after the code has completed. And I
don''t think I want to hold up the completion of the code process until the
email gets sent in case the email process takes longer on some machines
than
others.

I''m not sure if there is a better way to handle the attachment in the code
so I don''t have to save a file to the user''s desktop. Or if I can use a
deattach process that I can trigger from code to delete the file later.
Or
something else.

I''ve attached a snippet of the code below:

Thanks
Steve

------------

WordDoc.SaveAs(sSaveFileName)
Do While Not WordDoc.Saved
Application.DoEvents()
Loop
WordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChange s)

'' Email the Saved Merge Document.

Dim Fromaddress As New MailAddress("fromaddress")
Dim Toaddress As New MailAddress("toaddress")
Dim myMail As New MailMessage(Fromaddress, ToAddress)
myMail.Subject = "test"
Dim AttachmentFile As Attachment = New Attachment(sSaveFileName)
myMail.Attachments.Add(AttachmentFile)
myMail.Priority = MailPriority.High
Dim client As New SmtpClient
client.Host = "hostaddress"
client.Send(myMail)

'' Release the references.

WordMailMerge = Nothing
WordDoc = Nothing
WordApp = Nothing

'' Delete the temporary files.

System.IO.File.Delete(sSaveFileName)



这篇关于word automation vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆