Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Question about dlls needed for Word and VB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
News.Microsoft.com - 02 Oct 2006 06:28 GMT
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
Jean-Yves - 02 Oct 2006 13:59 GMT
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

> In my VB application I just added the capability of writing to a Word
> document.  I have a reference to
[quoted text clipped - 15 lines]
> Thanks
> Bill
News.Microsoft.com - 02 Oct 2006 15:34 GMT
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.

> Hi Bill
> Use late binding :
[quoted text clipped - 26 lines]
>> Thanks
>> Bill
Jean-Guy Marcil - 02 Oct 2006 18:00 GMT
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
[quoted text clipped - 26 lines]
> 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

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Howard Kaikow - 02 Oct 2006 18:13 GMT
Best solution is to get Office XP and compile with Office XP instead of
Office 2003.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.