Question about dlls needed for Word and VB

  • Thread starter News.Microsoft.com
  • Start date
N

News.Microsoft.com

In my VB application I just added the capability of writing to a Word
document. I have a reference to
Office11\msword.old in the project. My client is using Office XP. On my
machine, everything works fine. When I install the latest version of the
EXE using this new feature on the client's machine, it crashes saying
"ActiveX component can't create object". It occurs at the line,

Set MyWord = New Word.Application

So I surmise the problem is because they are running a different version of
Word and have different libraries. What files do I need to give them so
that they can use the feature of hooking up with Word? Do I need to have
them upgrade to the same version of Office I am using? Or is it a simple
matter of copying a few dlls/olb files and registering them on their
machines? When I look at Depends that comes with Enterprise, I don't even
see the references to the Office Dlls.

Thanks
Bill
 
J

Jean-Yves

Hi Bill
Use late binding :

Dim wdlApp As Object ' Declare variable to hold the reference.
Set wdApp = CreateObject("Word.application")
' You may have to set Visible property to True
' if you want to see the application.
wdApp.Visible = True
Regards
JY
 
N

News.Microsoft.com

Thanks that got me past the point of the "ActiveX component" error, but now
it is giving me "Type Mismatch" errors on the placing of data into the word
document from VB, even on my machine. If I switch it back to the early
binding it works fine. Here is the code.

Dim MyWord As Word.Application
Dim Path As String
Dim FileName As String
Dim Extension As String
Dim sWordDocument As String
Dim WordDoc As Word.Document

Path = "c:\"
FileName = "BuildingChangeForm"
Extension = ".Doc"
sWordDocument = Path + FileName + Extension
Set MyWord = New Word.Application
Set WordDoc = MyWord.Documents.Open(sWordDocument)
With MyWord
.Visible = True
.Options.Overtype = True
.ActiveDocument.bookmarks("BuildingNumber").Select
.Selection.TypeText USIComboRead(txtBuildingID)
.ActiveDocument.bookmarks("BuildingName").Select
.Selection.TypeText USIComboRead(cmbBuilding)
.ActiveDocument.bookmarks("BuildingAddress").Select
.Selection.TypeText txtBuildingAddress
ERRORS ON THIS LINE. Type mismatch. I do have a bookmark at that spot and
if I comment out that line then it happens a few lines later and if I
comment out that line, it happens a few lines later etc.
 
J

Jean-Guy Marcil

News.Microsoft.com was telling us:
News.Microsoft.com nous racontait que :
Thanks that got me past the point of the "ActiveX component" error,
but now it is giving me "Type Mismatch" errors on the placing of data
into the word document from VB, even on my machine. If I switch it
back to the early binding it works fine. Here is the code.

Dim MyWord As Word.Application
Dim Path As String
Dim FileName As String
Dim Extension As String
Dim sWordDocument As String
Dim WordDoc As Word.Document

Path = "c:\"
FileName = "BuildingChangeForm"
Extension = ".Doc"
sWordDocument = Path + FileName + Extension
Set MyWord = New Word.Application
Set WordDoc = MyWord.Documents.Open(sWordDocument)
With MyWord
.Visible = True
.Options.Overtype = True
.ActiveDocument.bookmarks("BuildingNumber").Select
.Selection.TypeText USIComboRead(txtBuildingID)
.ActiveDocument.bookmarks("BuildingName").Select
.Selection.TypeText USIComboRead(cmbBuilding)
.ActiveDocument.bookmarks("BuildingAddress").Select
.Selection.TypeText txtBuildingAddress
ERRORS ON THIS LINE. Type mismatch. I do have a bookmark at that
spot and if I comment out that line then it happens a few lines later
and if I comment out that line, it happens a few lines later etc.

I am not sure if this will solve your problem or not, but you should avoid
the Selection object as much as possible, especially when automating
documents.

Replace each pair of line by a single one like this:
.ActiveDocument.bookmarks("BuildingNumber").Select
.Selection.TypeText USIComboRead(txtBuildingID)
to be replaced by:

.ActiveDocument.bookmarks("BuildingNumber").Range.Text =
USIComboRead(txtBuildingID)

Also, Jean_Yves suggested that you use:
Dim wdlApp As Object ' Declare variable to hold the reference.
Set wdApp = CreateObject("Word.application")
but you are using:
Dim MyWord As Word.Application
Set MyWord = New Word.Application
Any particular reason?

For a more on late binding, see:
http://word.mvps.org/faqs/interdev/earlyvslatebinding.htm

Moreover, do not use ActiveDocument, especially when there might be more
than one document open. You already have a Document object, use it.
Declare it like this:
Dim WordDoc As Object
and use it like this:

Set MyWord = CreateObject("Word.application")
With MyWord
Set WordDoc = .Documents.Open(sWordDocument)
.Visible = True

'.Options.Overtype = True
'Is this necessary? I do not think so
'If it is, do not forget to reset the user setting
'I hate it when some code/application changes
'my settings without telling me
'Something like this

Dim boolUserOverType As Boolean
boolUserOverType = Options.Overtype
.Options.Overtype = True

With WordDoc
.Bookmarks("BuildingNumber").Range.Text =
USIComboRead(txtBuildingID)
.Bookmarks("BuildingName").Range.Text = USIComboRead(cmbBuilding)
'Etc.
End With
'If necessary:
.Options.Overtype = boolUserOverType
End With

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Howard Kaikow

Best solution is to get Office XP and compile with Office XP instead of
Office 2003.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top