本文介绍了后期绑定现在失败了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Word自动化有些麻烦。对它进行排序,在此过程中我认为我会尝试后期绑定。有些人推荐它。所以这个: *************************************** *********** ******* Public Sub MailMerge(strQuery As String,strTemplate As String) snip Dim doc As Word.Document Dim wrdApp As Word.Application snip 设置wrdApp = New Word.Application 设置doc = wrdApp.Documents.Add(strPath& strTemplate) 使用doc.MailMerge 。 .Destination = wdSendToNewDocument ..SuppressBlankLines = True 使用.DataSource ..FirstRecord = wdDefaultFirstRecord 。 .LastRecord = wdDefaultLastRecord 结束 如果.State = wdMainAndDataSource然后.Execute 结束 wrdApp。 Visible = True snip End Sub ******************** ****************************** ******* 工作,带参考单词olb 如果我将其更改为: ******************** ************** **************** ******* Public Sub MailMerge(strQuery As String,strTemplate As String) snip Dim doc As object Dim wrdApp as object snip 设置wrdApp = CreateObject(" Word.Application") 设置doc = wrdApp.Documents.Add(strPath& strTemplate) 使用doc.MailMerge ..Destination = wdSendToNewDocument ..SuppressBlankLines = True 使用.DataSource ..FirstRecord = wdDefaultFirstRecord ..LastRecord = wdDefaultLastRecord 结束 如果.State = wdMainAndDataSource然后.Execute 结束 wrdApp.Visible = True snip End Sub ******************************************* ******* ******* 停止 ..Destination = wdSendToNewDocument 并突出显示wdSendToNewDocument ''未知变量'' 有什么想法吗? TIA,Mike MacSween 解决方案 谢谢Turtle,它完美无缺。虽然我不太懂。如果 使用CreateObject()来使用自动化,我可以访问Word方法 和属性,为什么不是常量? 现在不确定在哪种方式摆动。似乎存在冲突。所有 文献说''使用早期绑定,除非有一个很好的理由不是'b $ b到'',而很多人说使用后期绑定。有人建议早期使用开发(获取intellisense等)然后更改为 分发。但是,如果我自己必须找到不变的价值,那么会失去一些优势。如果使用计算机辅助设备,我读到总是迟到。 Whaddya认为? 干杯,迈克 Had some trouble with Word automation. Sorted it, in the process thought Iwould try late binding. Some people reccomend it. So this:************************************************** *******Public Sub MailMerge(strQuery As String, strTemplate As String)snipDim doc As Word.DocumentDim wrdApp As Word.Applicationsnip Set wrdApp = New Word.ApplicationSet doc = wrdApp.Documents.Add(strPath & strTemplate) With doc.MailMerge..Destination = wdSendToNewDocument..SuppressBlankLines = TrueWith .DataSource..FirstRecord = wdDefaultFirstRecord..LastRecord = wdDefaultLastRecordEnd WithIf .State = wdMainAndDataSource Then .ExecuteEnd WithwrdApp.Visible = TruesnipEnd Sub************************************************** *******works, with a reference to the Word olb If i change it to:************************************************** *******Public Sub MailMerge(strQuery As String, strTemplate As String)snipDim doc As objectDim wrdApp as objectsnip Set wrdApp = CreateObject("Word.Application")Set doc = wrdApp.Documents.Add(strPath & strTemplate) With doc.MailMerge..Destination = wdSendToNewDocument..SuppressBlankLines = TrueWith .DataSource..FirstRecord = wdDefaultFirstRecord..LastRecord = wdDefaultLastRecordEnd WithIf .State = wdMainAndDataSource Then .ExecuteEnd WithwrdApp.Visible = TruesnipEnd Sub************************************************** *******it halts on..Destination = wdSendToNewDocumentwith wdSendToNewDocument highlighted and ''unknown variable'' Any ideas? TIA, Mike MacSween 解决方案 Thanks Turtle, that worked perfectly. Though I don'' really understand. Ifusing CreateObject() to use automation gives me access to the Word methodsand properties, why not the constants? Not sure which way to swing on this now. There seems to be a conflict. Allthe literature says ''use early binding unless there''s a very good reason notto'' whereas a lot of people say use late binding. Some advise using early indevelopment (to get the intellisense etc.) then change to late fordistribution. But if I''m going to have to find constant values myself thatloses some advantage. And I read to always use late if using MDEs. Whaddya think? Cheers, Mike 这篇关于后期绑定现在失败了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 15:20