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
early biding / code that will force use of Word 97 in
Automation?
Thanks,
Byron
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
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.
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.
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.
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.
-----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)
.
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
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.
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.