Word 2007的VB自动化 [英] VB automation of Word 2007

查看:76
本文介绍了Word 2007的VB自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VB中打开一个单词模板并将值添加到书签然后保存

文档,如pdf。当我关闭文档时,它会弹出

一个另存为对话框。它已经用pdf保存了文档,而

就是我想用它完成的。我怎么能告诉它关闭文件没有

提示我什么?


For Each Row As DataRow in myDt.Rows

Dim objWord As Application

Dim objDoc As Document

objWord = CreateObject(" Word.Application")

objDoc = objWord.Documents .Add(" c:\Collections.dotx")

objDoc.Bookmarks.Item(" CUSTNO")。Range.Text = row.Item(" custno")

objDoc.Bookmarks.Item(" DATE")。Range.Text = DateString()

objDoc.SaveAs(" c:\test\"& row .Item(" custno")&" Collection",
WdSaveFormat.wdFormatPDF)

objDoc.Close()

下一页

I open a word template in VB and add values to the bookmarks then save
the document as as pdf. When I then go to close the document it pops up
a save as dialog box. It''s already saved the document in pdf and that
is all I want done with it. How can I tell it to close the file without
prompting me for anything?

For Each row As DataRow In myDt.Rows
Dim objWord As Application
Dim objDoc As Document
objWord = CreateObject("Word.Application")
objDoc = objWord.Documents.Add("c:\Collections.dotx")
objDoc.Bookmarks.Item("CUSTNO").Range.Text = row.Item("custno")
objDoc.Bookmarks.Item("DATE").Range.Text = DateString()
objDoc.SaveAs("c:\test\" & row.Item("custno") & "Collection",
WdSaveFormat.wdFormatPDF)
objDoc.Close()
Next

推荐答案

CJ,


不要送你或任何东西,这不是不可能的

有人在看这个知道你问题答案的新闻组。

因为你说过你的主题如果它没有覆盖你的b $ b问题,那么它已经低了(这是一个非常特殊的孤立的VB自动化Word的b $ b问题)。 />

在你的情况下我会在办公室编程新闻组中问这个问题

,因为如果用VB,VBA,C#,Java,C ++完成它不会改变你的

问题,办公室课程中有一些东西可以自动创建

a弹出窗口。


Cor

cj2 < cj*@nospam.nospamschreef in bericht

news:up ******************** @ TK2MSFTNGP04.phx.gbl ..
CJ,

Not to send you away or anything, it is not impossible that there is
somebody watching this newsgroup who knows the answer on your question.
Because you have stated your subject in a way that it is not covering your
problem it is however already lower (It is about a very special isolated
problem of VB automation of Word).

In your case I would ask this question in an office programming newsgroup
because if it is done with VB, VBA, C#, Java, C++ does not change your
problem that there is in the office class something that automaticly creates
a popup.

Cor
"cj2" <cj*@nospam.nospamschreef in bericht
news:up********************@TK2MSFTNGP04.phx.gbl.. .

>我在VB中打开一个单词模板并将值添加到书签,然后像pdf一样保存
文档。当我关闭文档时,会弹出一个保存
对话框。它已经用pdf保存了文档,这就是我想用它完成的所有内容。我怎么能告诉它关闭文件而不提示我什么?


For Every Row As DataRow in myDt.Rows

Dim objWord作为应用程序

Dim objDoc As Document

objWord = CreateObject(" Word.Application")

objDoc = objWord.Documents.Add(" ; c:\Collections.dotx")

objDoc.Bookmarks.Item(" CUSTNO")。Range.Text = row.Item(" custno")

objDoc.Bookmarks.Item(" DATE")。Range.Text = DateString()

objDoc.SaveAs(" c:\test\"& row.Item(") ; custno")&" Collection",

WdSaveFormat.wdFormatPDF)

objDoc.Close()

下一个
>I open a word template in VB and add values to the bookmarks then save the
document as as pdf. When I then go to close the document it pops up a save
as dialog box. It''s already saved the document in pdf and that is all I
want done with it. How can I tell it to close the file without prompting
me for anything?

For Each row As DataRow In myDt.Rows
Dim objWord As Application
Dim objDoc As Document
objWord = CreateObject("Word.Application")
objDoc = objWord.Documents.Add("c:\Collections.dotx")
objDoc.Bookmarks.Item("CUSTNO").Range.Text = row.Item("custno")
objDoc.Bookmarks.Item("DATE").Range.Text = DateString()
objDoc.SaveAs("c:\test\" & row.Item("custno") & "Collection",
WdSaveFormat.wdFormatPDF)
objDoc.Close()
Next


Hello CJ,


将Word文档另存为PDF(另存为WdSaveFormat.wdFormatPDF)表现为

与将文档保存为Word格式不同,例如DOCX / DOC。让我们先看看问题的解决方案,然后我会解释为什么。


***决议***

更改代码行

objDoc.Close()



objDoc.Close(false)


换句话说,我们将false传递给参数SaveChange。关闭

方法,放弃更改Word文档。


***原因***

In事实上,此代码行仅*将当前Word文档导出为PDF

文件:

objDoc.SaveAs(" c:\\\ quot;& ; row.Item(" custno")&" Collection",

WdSaveFormat.wdFormatPDF)


它不保存当前的Word文档。因此,当我们用objDoc.Close关闭文档时,我们会得到一个SaveAs

对话框。


请尝试解决方案并让我知道它是否''对你有帮助。


PS正如Cor建议的那样,这个Office自动化更合适的新闻组

问题是

microsoft.public.office.developer.automation

列表管理的新闻组,请参阅页面
http://msdn.microsoft.com/en-us/subs.../aa974230.aspx


问候,

贾良戈(ji****@online.microsoft.com,删除''在线。'')

Microsoft在线社区支持


让我们的客户满意是我们的#1优先级。我们欢迎您的意见和

有关我们如何改进我们为您提供的支持的建议。请

随时让我的经理知道您对服务水平的看法

提供。您可以直接向我的经理发送反馈:
ms****@microsoft.com


========================================== ========

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========

此帖子按原样提供。没有保证,也没有授予任何权利。

Hello CJ,

Saving a Word document as PDF (SaveAs WdSaveFormat.wdFormatPDF) behaves
differently from saving the document as Word format, e.g. docx/doc. Let''s
first look at the resolution of the issue, then I will explain "WHY".

*** RESOLUTION ***
Change the code line
objDoc.Close()
to
objDoc.Close(false)

In other words, we pass false to the param "SaveChange" of the Close
method, to discard the change of the Word document.

*** CAUSE ***
In fact, this code line only *exports* the current Word document to a PDF
file:
objDoc.SaveAs("c:\test\" & row.Item("custno") & "Collection",
WdSaveFormat.wdFormatPDF)

It does not save the current Word document. Therefore, we get a SaveAs
dialog when we close the document with objDoc.Close()

Please try the solution and let me know whether it''s helpful to you or not.

P.S. As Cor suggested, a more proper newsgroup for this Office automation
issue is
microsoft.public.office.developer.automation
For the list of the managed newsgroups, please refer to the page
http://msdn.microsoft.com/en-us/subs.../aa974230.aspx

Regards,
Jialiang Ge (ji****@online.microsoft.com, remove ''online.'')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


谢谢,这就是我需要的。我明白你的意思是将

导出为pdf。然后,感觉它没有被保存,并希望将它保存在

退出。我无法找出close()的选项,但是他们现在感觉

感觉。


还要感谢你和Cor指出

Microsoft.public.office.developer.automation和组列表。

实际上这让我想知道是否有更好的方法来访问这些

组?现在我正在使用Mozilla Thunderbird并订阅

microsoft.public.dotnet.languages.vb。我喜欢我可以

标记发布忽略,我不会看到他们只留下我感兴趣的那些

主题的列表。我把它们放在Thunderbird所以如果我忘了,我可以稍后再回复给他们。大约3个月后我不喜欢这个

线程只显示文章已过期。我唯一的

解决方法是转到Google新闻组并搜索该组

然后搜索主题。他们还有它。


Jialiang Ge [MSFT]写道:
Thanks, that''s what I needed. I understand what you mean by exporting
to pdf. Word then feels like it isn''t saved and wants to save it upon
exiting. I could not figure out the options for close() but they make
sense now.

Also thanks to you and Cor for pointing out
Microsoft.public.office.developer.automation and the list of groups.
Actually this makes me wonder if there is a better way to access these
groups? Right now I''m using Mozilla Thunderbird and subscribe to
microsoft.public.dotnet.languages.vb for example. I like that I can
mark post Ignore and I don''t see them leaving only a list of those
threads I am interested in. I leave them in Thunderbird so I can refer
back to them later if I forget. I don''t like that after about 3 months
the threads only display that the article has expired. My only
workaround is going to Google NewsGroups and searching for the group
then for the subject of thread. They still have it.

Jialiang Ge [MSFT] wrote:

Hello CJ,

将Word文档另存为PDF(另存为WdSaveFormat.wdFormatPDF)的行为与将文档另存为Word格式不同,例如: DOCX / DOC。让我们先看看问题的解决方案,然后我会解释为什么。


***决议***

更改代码行

objDoc.Close()



objDoc.Close(false)


换句话说,我们将false传递给参数SaveChange。关闭

方法,放弃更改Word文档。


***原因***

In事实上,此代码行仅*将当前Word文档导出为PDF

文件:

objDoc.SaveAs(" c:\\\ quot;& ; row.Item(" custno")&" Collection",

WdSaveFormat.wdFormatPDF)


它不保存当前的Word文档。因此,当我们用objDoc.Close关闭文档时,我们会得到一个SaveAs

对话框。


请尝试解决方案并让我知道它是否''对你有帮助。


PS正如Cor建议的那样,这个Office自动化更合适的新闻组

问题是

microsoft.public.office.developer.automation

列表管理的新闻组,请参阅页面
http://msdn.microsoft.com/en-us/subs.../aa974230.aspx


问候,

贾良戈(ji****@online.microsoft.com,删除''在线。'')

Microsoft在线社区支持


让我们的客户满意是我们的#1优先级。我们欢迎您的意见和

有关我们如何改进我们为您提供的支持的建议。请

随时让我的经理知道您对服务水平的看法

提供。您可以直接向我的经理发送反馈:
ms****@microsoft.com


========================================== ========

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========

此帖子按原样提供。没有保证,也没有授予任何权利。
Hello CJ,

Saving a Word document as PDF (SaveAs WdSaveFormat.wdFormatPDF) behaves
differently from saving the document as Word format, e.g. docx/doc. Let''s
first look at the resolution of the issue, then I will explain "WHY".

*** RESOLUTION ***
Change the code line
objDoc.Close()
to
objDoc.Close(false)

In other words, we pass false to the param "SaveChange" of the Close
method, to discard the change of the Word document.

*** CAUSE ***
In fact, this code line only *exports* the current Word document to a PDF
file:
objDoc.SaveAs("c:\test\" & row.Item("custno") & "Collection",
WdSaveFormat.wdFormatPDF)

It does not save the current Word document. Therefore, we get a SaveAs
dialog when we close the document with objDoc.Close()

Please try the solution and let me know whether it''s helpful to you or not.

P.S. As Cor suggested, a more proper newsgroup for this Office automation
issue is
microsoft.public.office.developer.automation
For the list of the managed newsgroups, please refer to the page
http://msdn.microsoft.com/en-us/subs.../aa974230.aspx

Regards,
Jialiang Ge (ji****@online.microsoft.com, remove ''online.'')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


这篇关于Word 2007的VB自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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