VB.net中的邮件合并概念 [英] Mail Merge concept in VB.net
本文介绍了VB.net中的邮件合并概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码:
Dim wrdMailMerge As Word.MailMerge
myApp = CreateObject( Word.Application)
myDoc = myApp.Documents.Open( DOC.PATH)
wrdMailMerge = myDoc.MailMerge
wrdMailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdFormLetters
wrdMailMerge.Execute()
myApp.ActiveDocument .SaveAs( DOC.PATH)
wrdMailMerge.Execute()
在此行中抛出下面给出的错误,
此方法或属性不是因为当前邮件合并主文档需要数据源。
我想连接没有DSN的邮件合并。
请帮帮我。
问候
Rajesh V
解决方案
我个人以前从未这样做过,但只是从阅读错误信息中听起来就像你需要的那样设置数据源。如果您要在Word中手动邮件合并文档,则必须为其提供数据源。例如,如果您的word文档是一个字母,并且您希望将合并邮件合并到包含名称和地址的逗号分隔文本文件,则您的数据源将是.txt文件。
你可以从谷歌一> [ ^ ]。
第一个结果这里 [ ^ ]有一个代码示例。
objWord.ActiveDocument。 MailMerge.OpenDataSource( 您的数据库路径,_
连接:= dsn = DSN NAME; dbq =& YOUR DATABASE PATH& ;,_
sqlstatement:= select * from& tableName& )
此人似乎在使用数据库(不是像我在上面假设的场景中那样的文本文件)所以你必须研究如何连接你正在使用的任何来源。
希望这有帮助。
Dim objWord As < span class =code-keyword>新 对象
objWord = CreateObject( Word.Application)' 创建word应用程序
objWord.application.WindowState = 0 ' 设置单词窗口正常状态(Const wdWindowStatENormal = 0)
objWord.Documents.Open(System.AppDomain.CurrentDomain.BaseDirectory()& \ WORD.doc)
objWord.ActiveDocument.MailMerge.OpenDataSource(_
名称:= System.AppDomain.CurrentDomain.BaseDirectory()& ACCESSDB.mdb ,_
连接:= Provider = Microsoft.Jet.OLEDB.4.0; Data Source = ACCESSDB.mdb ; Mode = Read;,_
SQLStatement:= select * fromTABLE_NAME ,_
SubType:= Word.WdMergeSubType.wdMergeSubTypeAccess)
objWord.ActiveDocument.MailMerge.Execute()
objWord.ActiveDocument.SaveAs(System.AppDomain.CurrentDomain.BaseDirectory ()& \ WORD1.DOC)
objWord.Parent.Windows( 2 )。关闭(Word.WdSaveOptions.wdDoNotSaveChanges)
objWord.Visible = Tru ë跨度>
hi,
My Code:
Dim wrdMailMerge As Word.MailMerge
myApp = CreateObject("Word.Application")
myDoc = myApp.Documents.Open("DOC. PATH")
wrdMailMerge = myDoc.MailMerge
wrdMailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdFormLetters
wrdMailMerge.Execute()
myApp.ActiveDocument.SaveAs("DOC. PATH")
wrdMailMerge.Execute()
in this line throwing Error given below,
This method or property is not available because the current mail merge main document needs a data source.
I want to connect mail merge without DSN.
pls help me out.
Regards
Rajesh V
解决方案
I''ve personally never done this before, but just from reading the error message it sounds like you need to set a datasource. If you were going to manually mail merge a document in Word, you''d have to provide a datasource for it. For example, if your word document was a letter and you wanted to mail merge to a comma delimited text file that contained names and addresses, your data source would be the .txt file.
You can find some general help just from google[^].
The first result here[^] has a code sample.
objWord.ActiveDocument.MailMerge.OpenDataSource("YOUR DATABASE PATH", _ Connection:="dsn=DSN NAME; dbq=" & YOUR DATABASE PATH & ";", _ sqlstatement:="select * from `" & tableName & "`")
This person appears to be using a database (not a textfile like in the scenario I hypothetically made above) so you''ll have to research how to connect to whatever source you are using.
Hope this helps.
Dim objWord As New Object objWord = CreateObject("Word.Application") ' Creating a word application objWord.application.WindowState = 0 ' set the word window in normal state (Const wdWindowStatENormal = 0) objWord.Documents.Open(System.AppDomain.CurrentDomain.BaseDirectory() & "\WORD.doc") objWord.ActiveDocument.MailMerge.OpenDataSource( _ Name:=System.AppDomain.CurrentDomain.BaseDirectory() & "ACCESSDB.mdb", _ Connection:="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ACCESSDB.mdb;Mode=Read;", _ SQLStatement:="select * from `TABLE_NAME`", _ SubType:=Word.WdMergeSubType.wdMergeSubTypeAccess) objWord.ActiveDocument.MailMerge.Execute() objWord.ActiveDocument.SaveAs(System.AppDomain.CurrentDomain.BaseDirectory() & "\WORD1.DOC") objWord.Parent.Windows(2).Close(Word.WdSaveOptions.wdDoNotSaveChanges) objWord.Visible = True
这篇关于VB.net中的邮件合并概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文