Hi Raymond,
The code works like it's supposed to from within Excel VBA without
modification
Excel VBA is irrelevant when you're working with Word. The two object models
are in no respect the same. You cannot take code from one and use it in the
other.
I've yet to install the PIAs. Does Access 2003 also require a PIA install?
(The rest of my Office suite is 2002.)
Whether or not you need the PIA for any particular applications depends on
whether you're planning to automate the application interface. Under most
circumstances I wouldn't expect you to need to automate Access, as you'd use
the ADO.NET capabilities to work with the data...
But if you haven't installed any PIAs, how is that you're able to test the code
you show us? (I suppose, if the PIAs aren't present, your project may have
automatically created a set of IAs...)
Notice the 2 "Imports....." statements at the top. Why do you have to have
these statments? The items referred to are in the Word namespace which is
referenced, so VB already knows it's there. Evidently you have to reference
and import, both????
Imports Word.WdWordDialog
Imports Word.WdSaveOptions
As far as I know, you shouldn't need either of these. I suppose you could have
them, as it would shorten the code lines when you need to use the Enums they
hold. But at some point your code will become unreadable if you do this a
lot...
On Error Resume Next
myWord = GetObject(, "Word.Application")
I strongly urge you to NOT use this in your .NET code. Use the Try...Catch
blocks for your error handling. And use the .NET Framework equivalent of
GetObject: GetActiveObject()
If you search the VSTO forum (
http://forums.microsoft.com/msdn/showforum.aspx?
forumid=16&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=0) on MSDN you'll find a
number of examples how to use this method.
'Make sure you release object references.
myWord = Nothing
myDoc = Nothing
myDialog = Nothing
You're doing this in the wrong order. You need to release objects in the
reverse order they were instantiated. If you release the application object
(myWord) first, then myDoc and myDialog are "orphaned" and cannot be released:
they both depend on the Application object for their existance.
myDialog = myWord.Dialogs(wdDialogEditReplace)
With myDialog
..Find = "Hi" 'Bombs here
As I mentioned before, you should work with Word's object model, not over the
Dialog for this... Do you have Option Strict On in your project? If you do, you
won't be able to use late-binding the same way the classic VB languages can.
You'd need to use PInvoke (GetType().InvokeMember). That's not a simply way to
proceed...
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail