Startement to force use of Word 97

B

Byron

What statement do I need to use to specify "Word.8" in my
early biding / code that will force use of Word 97 in
Automation?

Thanks,

Byron
 
S

solex

Assuming that you have office 97 installed on your PC you would set a
reference to the Word 8.0 Object Library.

Dan
 
B

Byron

I do have my reference set to Word 8.0, but when I
execute the code to set the reference:

Set wordApp = GetObject(, "Word.Application")

then open the document:

strDocName = "D:\MyPath\MyDocumentName.doc"
Set WordDoc = wordApp.Documents.Open(strDocName)

It still opens in Word 2002. I have both installed on my
machine.

Thanks for any help.

Byron
 
B

Byron

Doug,

Thanks for the reply, however, I could not make that work
either. I have tried several ways to declare it with no
success.

If you have any other ideas I would appreciate the info.

Byron
 
S

solex

Try using early binding instead of late binding:

Dim wordApp as Word.Application

Set wordApp = New Word.Application

Regards,
Dan
 
B

Byron

Dan,

Thanks for your reply.

I have now tried your statement, but Word 2002 still is
being opened and opening my document.

I have a reference to Word 8.0 set and have tried
everything that has been suggested. I still am not able
to force Word 97 to be used to open the documents.

Any help will be appreciated.

Byron
 
D

Dirk Goldgar

Byron said:
Dan,

Thanks for your reply.

I have now tried your statement, but Word 2002 still is
being opened and opening my document.

I have a reference to Word 8.0 set and have tried
everything that has been suggested. I still am not able
to force Word 97 to be used to open the documents.

Any help will be appreciated.

Byron

Did you try

Dim wordApp As Word.Application.8
Set wordApp = New Word.Application.8

strDocName = "D:\MyPath\MyDocumentName.doc"
Set WordDoc = wordApp.Documents.Open(strDocName)

? I can't try that myself, because I only have one version of Word
installed.
 
B

Byron

Dirk,

I have just now tried your statements and I get a syntax
error. If I could just declare the object as .8 in any
way, then it might just have a chance to work.

I have tried just about every possible combination to
declare with the .8. I even tried Word 97 and other
variations with no luck.

Thank for your help. If you have any new ways of trying
this, please let me know.

Byron
 
D

Dirk Goldgar

Byron said:
Dirk,

I have just now tried your statements and I get a syntax
error. If I could just declare the object as .8 in any
way, then it might just have a chance to work.

I have tried just about every possible combination to
declare with the .8. I even tried Word 97 and other
variations with no luck.

Thank for your help. If you have any new ways of trying
this, please let me know.

Try this:

Dim wordApp As Object
Dim strDocName As String

Set wordApp = CreateObject("Word.Application.8")

strDocName = "D:\MyPath\MyDocumentName.doc"
Set WordDoc = wordApp.Documents.Open(strDocName)

I don't have Word 97 handy to try it out, but similar code allows me to
open Access 97 from an Access 2002 database.
 
B

Byron

Dirk,

Thanks for the code. When I use your code it does not
cause any errors. However, the application is still
opening Word 2003.

Any other ideas. I have a reference only ot Word 8 and
have tried everything.

One of the reasons that I am attempting to just force
Word 8 to open is that I have having problems with Word
2002 being consistant to open a specified document. One
time it will and the second time it may not. This
inconsistancy is not acceptable when producing an
application for a client.

If you have any thoughts along this line I would
appreciate any help.

Byron
 
D

Dirk Goldgar

Byron said:
Dirk,

Thanks for the code. When I use your code it does not
cause any errors. However, the application is still
opening Word 2003.

Any other ideas. I have a reference only ot Word 8 and
have tried everything.

I'm pretty much at a loss, I'm afraid, since I don't have an older
version of Word installed to test with. As I said, my code worked fine
for creating an instance of Access 97, even with Access 2002 (and Access
2000) installed. The only thing I can think of it to make sure that
Word 97 is properly registered with the OS, so that your
"Word.Application.8" can be resolved.
One of the reasons that I am attempting to just force
Word 8 to open is that I have having problems with Word
2002 being consistant to open a specified document. One
time it will and the second time it may not. This
inconsistancy is not acceptable when producing an
application for a client.

That means, of course, that you're going to insist that the users of
your application all have Word 97 installed. That could be problematic.
If I were in your shoes, I think I'd be addressing the original problem
with Word 2002 (or 2003 -- which is it?), rather than trying to force
the loading of Word 97.
 
B

Byron

Dirk,

Well, you are quite correct in your evaluation of the
situation. And by the way, it is Word 2002 not 2003.

I am back now to trying to make Word 2002 be more
consistant. What actually started the whole thing, is
that I was preparing to do a presentation on Automation
using PowerPoint. I wanted to have a button on a slide
that would open one of my existing applications that
merges information to one of several chosen Word
documents. Well when I attempted to use it in this manner
I started getting these strange results and it has just
escalated from there.

Right now I am back to just trying to get a stable
environment where I can demo some things to some
potential clients. When I start up my Access application
which I have now converted to Access 2002, it starts with
no problem. When I attempt to open the Word document it
may or may not complete the task. It will always open an
instance of Word, but may not open the document. (This
never happened using Word 97, thus the attempt to revert
back to 97). In any event if I try the same document
again, I get the message to the effect: "The document did
not load correctly and a serious error occurred." If I
continue, it may or may not load the document. If I try
it again (third time) it will present another message
about opening the document and when I confirm that
message, the document will usually open. This
inconsistancy has just about driven me over the edge.

I have just been testing again after using the following
statements and seem to have a little better results, but
I am still concerned about looking like a fool in front
of my potential clients.

On Error GoTo CreateWordApp
Set wordApp = GetObject(, "Word.Application")
strDocName = "D:\FullPath\MergeDocName.doc"
Set WordDoc = wordApp.Documents.Open(strDocName)
With wordApp
' Make the application visible
.Visible = True
' Move to each bookmark and insert text from the form
.ActiveDocument.Bookmarks("Company").Select
.Selection.Text = (CStr(Me![Co-Name]))
.ActiveDocument.Bookmarks("Contact").Select
.Selection.Text = (CStr(Me![frmContacts].Form!
[ContactName]))
.ActiveDocument.Bookmarks("Address").Select
.Selection.Text = (CStr(Me![Mail-Address1]))
.ActiveDocument.Bookmarks("City").Select
.Selection.Text = (CStr(Me![Mail-City]))
.ActiveDocument.Bookmarks("ST").Select
.Selection.Text = (CStr(Me![Mail-State]))
.ActiveDocument.Bookmarks("Zip").Select
.Selection.Text = (CStr(Me![Mail-Zip]))
.ActiveDocument.Bookmarks("Greeting").Select
.Selection.Text = (CStr(fName))
End With
wordApp.Visible = True
wordApp.Windows(wordApp.Windows.Count).Activate

' AppActivate "Microsoft Word"
wordApp.Activate
wordApp.WindowState = 0 'wdWindowStateRestore
CreateWordApp:
Set wordApp = CreateObject("Word.Application")
Resume Next

Any other observations you may have, or suggestions would
be appreciated.

Thanks for you time.

Byron
 
D

Dirk Goldgar

Byron said:
Dirk,

Well, you are quite correct in your evaluation of the
situation. And by the way, it is Word 2002 not 2003.

I am back now to trying to make Word 2002 be more
consistant. What actually started the whole thing, is
that I was preparing to do a presentation on Automation
using PowerPoint. I wanted to have a button on a slide
that would open one of my existing applications that
merges information to one of several chosen Word
documents. Well when I attempted to use it in this manner
I started getting these strange results and it has just
escalated from there.

Right now I am back to just trying to get a stable
environment where I can demo some things to some
potential clients. When I start up my Access application
which I have now converted to Access 2002, it starts with
no problem. When I attempt to open the Word document it
may or may not complete the task. It will always open an
instance of Word, but may not open the document. (This
never happened using Word 97, thus the attempt to revert
back to 97). In any event if I try the same document
again, I get the message to the effect: "The document did
not load correctly and a serious error occurred." If I
continue, it may or may not load the document. If I try
it again (third time) it will present another message
about opening the document and when I confirm that
message, the document will usually open. This
inconsistancy has just about driven me over the edge.

I have just been testing again after using the following
statements and seem to have a little better results, but
I am still concerned about looking like a fool in front
of my potential clients.

On Error GoTo CreateWordApp
Set wordApp = GetObject(, "Word.Application")
strDocName = "D:\FullPath\MergeDocName.doc"
Set WordDoc = wordApp.Documents.Open(strDocName)
With wordApp
' Make the application visible
.Visible = True
' Move to each bookmark and insert text from the form
.ActiveDocument.Bookmarks("Company").Select
.Selection.Text = (CStr(Me![Co-Name]))
.ActiveDocument.Bookmarks("Contact").Select
.Selection.Text = (CStr(Me![frmContacts].Form!
[ContactName]))
.ActiveDocument.Bookmarks("Address").Select
.Selection.Text = (CStr(Me![Mail-Address1]))
.ActiveDocument.Bookmarks("City").Select
.Selection.Text = (CStr(Me![Mail-City]))
.ActiveDocument.Bookmarks("ST").Select
.Selection.Text = (CStr(Me![Mail-State]))
.ActiveDocument.Bookmarks("Zip").Select
.Selection.Text = (CStr(Me![Mail-Zip]))
.ActiveDocument.Bookmarks("Greeting").Select
.Selection.Text = (CStr(fName))
End With
wordApp.Visible = True
wordApp.Windows(wordApp.Windows.Count).Activate

' AppActivate "Microsoft Word"
wordApp.Activate
wordApp.WindowState = 0 'wdWindowStateRestore
CreateWordApp:
Set wordApp = CreateObject("Word.Application")
Resume Next

Any other observations you may have, or suggestions would
be appreciated.

I'm no expert on Word, Byron, so you may want to take your questions to
one of the Word newsgroups. I do see an error in the code as posted,
though: there is nothing to stop the code from falling through to the
CreateWordApp logic, and *any* error is also going to transfer control
to that point, even after you've successfully gotten yourself a Word
application object. You may want to do something like this:

'----- start of revised code -----
Sub MakeWordDoc()

' Get existing Word application or create a new one if necessary.
On Error GoTo CreateWordApp ' special error handler
Set wordApp = GetObject(, "Word.Application")
On Error GoTo NormalErrorHandler ' back to normal

' ... body of code goes here ...

Exit_Point:
Set wordApp = Nothing
Exit Sub

CreateWordApp:
' Control comes here if GetObject fails.
Set wordApp = CreateObject("Word.Application")
Resume Next

NormalErrorHandler:
' Control comes here on any other error.
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Sub
'----- end of revised code -----
 
B

Byron

Dirk,

Thank you very much for sticking with me on this one. I
do have a line of code in my actual code to handle the
normal errors:
On Error Resume Next
I have just copied and pasted the code that I felt would
be important to our discussion.

I will take my other issues to one of the Word discussion
groups.

Again, thanks for the extra effort you gave to this one.

Byron
-----Original Message-----
Dirk,

Well, you are quite correct in your evaluation of the
situation. And by the way, it is Word 2002 not 2003.

I am back now to trying to make Word 2002 be more
consistant. What actually started the whole thing, is
that I was preparing to do a presentation on Automation
using PowerPoint. I wanted to have a button on a slide
that would open one of my existing applications that
merges information to one of several chosen Word
documents. Well when I attempted to use it in this manner
I started getting these strange results and it has just
escalated from there.

Right now I am back to just trying to get a stable
environment where I can demo some things to some
potential clients. When I start up my Access application
which I have now converted to Access 2002, it starts with
no problem. When I attempt to open the Word document it
may or may not complete the task. It will always open an
instance of Word, but may not open the document. (This
never happened using Word 97, thus the attempt to revert
back to 97). In any event if I try the same document
again, I get the message to the effect: "The document did
not load correctly and a serious error occurred." If I
continue, it may or may not load the document. If I try
it again (third time) it will present another message
about opening the document and when I confirm that
message, the document will usually open. This
inconsistancy has just about driven me over the edge.

I have just been testing again after using the following
statements and seem to have a little better results, but
I am still concerned about looking like a fool in front
of my potential clients.

On Error GoTo CreateWordApp
Set wordApp = GetObject(, "Word.Application")
strDocName = "D:\FullPath\MergeDocName.doc"
Set WordDoc = wordApp.Documents.Open(strDocName)
With wordApp
' Make the application visible
.Visible = True
' Move to each bookmark and insert text from the form
.ActiveDocument.Bookmarks("Company").Select
.Selection.Text = (CStr(Me![Co-Name]))
.ActiveDocument.Bookmarks("Contact").Select
.Selection.Text = (CStr(Me![frmContacts].Form!
[ContactName]))
.ActiveDocument.Bookmarks("Address").Select
.Selection.Text = (CStr(Me![Mail-Address1]))
.ActiveDocument.Bookmarks("City").Select
.Selection.Text = (CStr(Me![Mail-City]))
.ActiveDocument.Bookmarks("ST").Select
.Selection.Text = (CStr(Me![Mail-State]))
.ActiveDocument.Bookmarks("Zip").Select
.Selection.Text = (CStr(Me![Mail-Zip]))
.ActiveDocument.Bookmarks("Greeting").Select
.Selection.Text = (CStr(fName))
End With
wordApp.Visible = True
wordApp.Windows(wordApp.Windows.Count).Activate

' AppActivate "Microsoft Word"
wordApp.Activate
wordApp.WindowState = 0 'wdWindowStateRestore
CreateWordApp:
Set wordApp = CreateObject("Word.Application")
Resume Next

Any other observations you may have, or suggestions would
be appreciated.

I'm no expert on Word, Byron, so you may want to take your questions to
one of the Word newsgroups. I do see an error in the code as posted,
though: there is nothing to stop the code from falling through to the
CreateWordApp logic, and *any* error is also going to transfer control
to that point, even after you've successfully gotten yourself a Word
application object. You may want to do something like this:

'----- start of revised code -----
Sub MakeWordDoc()

' Get existing Word application or create a new one if necessary.
On Error GoTo CreateWordApp ' special error handler
Set wordApp = GetObject(, "Word.Application")
On Error GoTo NormalErrorHandler ' back to normal

' ... body of code goes here ...

Exit_Point:
Set wordApp = Nothing
Exit Sub

CreateWordApp:
' Control comes here if GetObject fails.
Set wordApp = CreateObject("Word.Application")
Resume Next

NormalErrorHandler:
' Control comes here on any other error.
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point

End Sub
'----- end of revised code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
D

Dirk Goldgar

Byron said:
Dirk,

Thank you very much for sticking with me on this one. I
do have a line of code in my actual code to handle the
normal errors:
On Error Resume Next

Do you then check Err.Number after each operation to ensure that no
error has occurred? If not, you may never see the error that is at the
root of your problems. My advice would be to use "On Error Resume Next"
very sparingly, and institute comprehensive error-handling instead.
I have just copied and pasted the code that I felt would
be important to our discussion.

I understand. In the future, though, please indicate in your post when
you've done something like that. Otherwise, one can end up on a wild
goose chase. In this particular case, I'd think the presence of an "On
Error Resume Next" statement would be relevant to the discussion.
I will take my other issues to one of the Word discussion
groups.

Good luck! If you find the explanation, please post back.
 

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