?
Solved

Closing a document under NT 4.0 & Office 97 results in an error, what am i doing wrong?

Posted on 2003-02-20
7
Medium Priority
?
130 Views
Last Modified: 2010-05-01
Hello,
I made myself a little program that opens a word-document and gives the user the possibility to fill in some bookmarks through a form with textfields. I programmed it all on a W2k machine, with Office 97. But when I start the program on a NT 4.0 machine with Office 97 all goes well until my code does this:

Dim WD As Word.Application
Dim Doc As Word.Document

Doc.Close
Set Doc = Nothing
WD.Quit
Set WD = Nothing

On Doc.close it gives me the error message:

'An action cannot be completed because a component (Microsoft Word - Document1) is not responding.'

Does anyone know what I should do to make it work again?
0
Comment
Question by:Asko
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 11

Expert Comment

by:Steiner
ID: 7987195
How did you assign a document to your object Doc?

I ask this, because you said that you opened a word document, but the name "Document1" sounds like a newly created one. Maybe Word wants to ask you whether to save this new document and therefore is busy and unable to close it.
How you deal with this problem depends whether Document1 is a document you really want or something that was created accidently.

Greets
Steiner
0
 

Author Comment

by:Asko
ID: 7987250
Thnx for your quick answer Steiner,

You are right, I am opening a new document which comes from a template. The user is not able to put anything in the document until they finished filling all the textfields and press an OK-button. But they also have the option to cancel by pressing a CANCEL-button (how appropriate). The text they already filled in has not yet been written to the document. So the document stays a new document until they press OK, which also automatically exits my program and lets them continue in Word...
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7987689
Maybe, the document is in "editing" state when you try to close it, did you save it before try to close? or,at least have been using

doc.saved=True
doc.close
....
....
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Accepted Solution

by:
Steiner earned 150 total points
ID: 7991913
It looks to me as if the new document is never saved, is that right? If that is so, Word wants to ask whether it should be saved and therefore is unable to close the document correctly.
I assume you want the document saved before you exit word? A quick of doing so could be an integrated Word-Dialog:

Sub Save()
    Dim sPath$, Dia As Dialog
   
    Set Dia = Application.Dialogs(wdDialogFileSaveAs)
    If Dia.Show <> 0 Then ActiveDocument.SaveAs Dia.Name
End Sub

If your document is saved, the close method should work. If the user selects cancel in the dialog, the dialog returns 0. Then use Doc.Saved=True, the document won't be saved, but Word thinks it was saved and therefore will not ask again.

Greets
Steiner
0
 

Author Comment

by:Asko
ID: 7992449
Thank you both for helping me out. I tried both of your suggestions. But they both did not exactly do what i wanted the CANCEL-button to do. I think I found out what the problem was myself: I had to test my program on NT 4.0 with Office 97, so I installed a PC with NT 4.0 and Off. 97. What i did not yet do was startup word from scratch and verify my name and company (the little dialogbox that pops up the first time you use Word). When i did that, and tried the program again, it worked fine! Seems like a little mistake from me!

Nevertheless I am going to award the points to Steiner, also because I can use his saving-code for my OK-button!

Thnx
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8001882
Then, why did you punish him with "B" grade?
If you need more details, just ask for them before accept the comment and to use a "B" grade.
0
 
LVL 11

Expert Comment

by:Steiner
ID: 8006542
Good question...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question