?
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
?
131 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

569 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