后期绑定现在失败了 [英] Late binding now failing

查看:101
本文介绍了后期绑定现在失败了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

wdSendToNewDocument

在Word中定义。

如果你没有对该库的引用,你就不能解析这个名字。


如果你有对图书馆的引用,你可以找到数字值

wdSendToNewDocument

并将其放入您的代码中。我看到有更多这些术语

来自Word olb你必须做同样的事情,如果你想删除

引用olb 。


HTH

- Turtle


" Mike MacSween" < MI ****************** @ btinternet.com>在消息中写道

新闻:3f ********************* @ pubnews.gradwell.net。 ..

Word自动化有些麻烦。对它进行排序,在此过程中我会尝试后期绑定。有些人推荐它。所以这个:
***************************************** ******* *******
Public Sub MailMerge(strQuery As String,strTemplate As String)
snip
Dim doc As Word.Document
Dim wrdApp作为Word.Application
snip

设置wrdApp =新的Word.Application
设置doc = wrdApp.Documents.Add(strPath& strTemplate)

>使用doc.MailMerge
。目的= wdSendToNewDocument
.SuppressBlankLines = True
使用.DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
结束
如果.State = wdMainAndDataSource然后.Execute
结束
wrdApp.Visible = True
剪辑
结束子
******** ****************************************** *******
作品,参考Word olb
如果我改成它:
******************** ****************************** *******
Public Sub MailMerge(strQuery As String,strTemplate作为String)
剪辑
Dim doc As obj等dim wrdApp作为对象
snip

设置wrdApp = CreateObject(" Word.Application")
设置doc = wrdApp.Documents.Add(strPath& strTemplate)

使用doc.MailMerge
。目的= wdSendToNewDocument
.SuppressBlankLines = True
使用.DataSource
.FirstRecord = wdDefaultFirstRecord
。 LastRecord = wdDefaultLastRecord
结束
如果.State = wdMainAndDataSource然后.Execute
结束
wrdApp.Visible = True
snip
End Sub ************************************************* * *******
它停止了
。目标= wdSendToNewDocument
wdSendToNewDocument突出显示和''未知变量''

任何想法?

TIA,Mike MacSween



Mike,


wdSendToNewDocument是一个命名常数或类似的东西。什么

如果你作弊并做了类似


?wdSendToNewDocument


在即时窗口中,获取数字/值与此

变量相关并使用该数字代替?它有用吗?


只是一个随意的猜测,所以不要花费超过30秒

玩它...

" MacDermott" <毫安******** @ nospam.com>在消息中写道

新闻:WF ****************** @ newsread1.news.atl.earth link.net ...

wdSendToNewDocument
在Word中定义。
如果您没有对该库的引用,则无法解析此
名称。
如果你有对库的引用,你可以找到wdSendToNewDocument的数值

并将其放入你的代码中。我看到有更多这些术语
来自Word olb你必须做同样的事情,如果你想删除
对olb的引用。




谢谢Turtle,它完美无缺。虽然我不太懂。如果

使用CreateObject()来使用自动化,我可以访问Word方法

和属性,为什么不是常量?


现在不确定在哪种方式摆动。似乎存在冲突。所有

文献说''使用早期绑定,除非有一个很好的理由不是'b $ b到'',而很多人说使用后期绑定。有人建议早期使用
开发(获取intellisense等)然后更改为

分发。但是,如果我自己必须找到不变的价值,那么
会失去一些优势。如果使用计算机辅助设备,我读到总是迟到。


Whaddya认为?


干杯,迈克


Had some trouble with Word automation. Sorted it, in the process thought I
would try late binding. Some people reccomend it. So this:
************************************************** *******
Public Sub MailMerge(strQuery As String, strTemplate As String)
snip
Dim doc As Word.Document
Dim wrdApp As Word.Application
snip

Set wrdApp = New Word.Application
Set doc = wrdApp.Documents.Add(strPath & strTemplate)

With doc.MailMerge
..Destination = wdSendToNewDocument
..SuppressBlankLines = True
With .DataSource
..FirstRecord = wdDefaultFirstRecord
..LastRecord = wdDefaultLastRecord
End With
If .State = wdMainAndDataSource Then .Execute
End With
wrdApp.Visible = True
snip
End Sub
************************************************** *******
works, with a reference to the Word olb

If i change it to:
************************************************** *******
Public Sub MailMerge(strQuery As String, strTemplate As String)
snip
Dim doc As object
Dim wrdApp as object
snip

Set wrdApp = CreateObject("Word.Application")
Set doc = wrdApp.Documents.Add(strPath & strTemplate)

With doc.MailMerge
..Destination = wdSendToNewDocument
..SuppressBlankLines = True
With .DataSource
..FirstRecord = wdDefaultFirstRecord
..LastRecord = wdDefaultLastRecord
End With
If .State = wdMainAndDataSource Then .Execute
End With
wrdApp.Visible = True
snip
End Sub
************************************************** *******
it halts on
..Destination = wdSendToNewDocument
with wdSendToNewDocument highlighted and ''unknown variable''

Any ideas?

TIA, Mike MacSween

解决方案

wdSendToNewDocument
is defined in the Word olb.
If you don''t have a reference to that library, you can''t resolve this name.

If you do have a reference to the library, you can find the numeric value of
wdSendToNewDocument
and put that into your code. I see there are a couple more of these terms
from the Word olb you''ll have to do the same with if you want to remove the
reference to the olb.

HTH
- Turtle

"Mike MacSween" <mi******************@btinternet.com> wrote in message
news:3f*********************@pubnews.gradwell.net. ..

Had some trouble with Word automation. Sorted it, in the process thought I
would try late binding. Some people reccomend it. So this:
************************************************** *******
Public Sub MailMerge(strQuery As String, strTemplate As String)
snip
Dim doc As Word.Document
Dim wrdApp As Word.Application
snip

Set wrdApp = New Word.Application
Set doc = wrdApp.Documents.Add(strPath & strTemplate)

With doc.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
If .State = wdMainAndDataSource Then .Execute
End With
wrdApp.Visible = True
snip
End Sub
************************************************** *******
works, with a reference to the Word olb

If i change it to:
************************************************** *******
Public Sub MailMerge(strQuery As String, strTemplate As String)
snip
Dim doc As object
Dim wrdApp as object
snip

Set wrdApp = CreateObject("Word.Application")
Set doc = wrdApp.Documents.Add(strPath & strTemplate)

With doc.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
If .State = wdMainAndDataSource Then .Execute
End With
wrdApp.Visible = True
snip
End Sub
************************************************** *******
it halts on
.Destination = wdSendToNewDocument
with wdSendToNewDocument highlighted and ''unknown variable''

Any ideas?

TIA, Mike MacSween



Mike,

wdSendToNewDocument is a named constant or something like that. What
if you cheat and do something like

?wdSendToNewDocument

in the immediate window, get the number/value associated with this
variable and use that number instead? Does it work?

just a haphazard guess, so don''t spend any more than 30 seconds
playing with it...


"MacDermott" <ma********@nospam.com> wrote in message
news:WF******************@newsread1.news.atl.earth link.net...

wdSendToNewDocument
is defined in the Word olb.
If you don''t have a reference to that library, you can''t resolve this name.
If you do have a reference to the library, you can find the numeric value of wdSendToNewDocument
and put that into your code. I see there are a couple more of these terms
from the Word olb you''ll have to do the same with if you want to remove the reference to the olb.



Thanks Turtle, that worked perfectly. Though I don'' really understand. If
using CreateObject() to use automation gives me access to the Word methods
and properties, why not the constants?

Not sure which way to swing on this now. There seems to be a conflict. All
the literature says ''use early binding unless there''s a very good reason not
to'' whereas a lot of people say use late binding. Some advise using early in
development (to get the intellisense etc.) then change to late for
distribution. But if I''m going to have to find constant values myself that
loses some advantage. And I read to always use late if using MDEs.

Whaddya think?

Cheers, Mike


这篇关于后期绑定现在失败了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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