RPC server is unavailable
-
12. dubna 2012 4:18i have used word in my application, it will open the word supported file as expected but wheni have close that file form_closing event gets fired. if word process WINWORD.exe is not running while checking document.saved() in IF,the application gives exception as "RPC server is unavailable."
Všechny reakce
-
13. dubna 2012 5:17Moderátor
Hi CoolMayur,
Welcome to the MSDN forum.
Would you like to provide the code about “checking document.saved() in IF”. The document.saved method can’t be the judgment of if statement. If the method failed (your situation), the VS will stop the application and give you an exception instead of return a False value to the IF.
In my opinion, you can avoid doing this. You can force the word to save the file when you close the word in your application. Here is a sample:
ObjDoc.Close(SaveChanges:=True)
Hope this helps. If I misunderstood, please feel free to let me know.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
- Upravený Mark Liu-lxfModerator 13. dubna 2012 5:19
-
13. dubna 2012 5:28Thanks for reply
What to do in case word process get closed from out side of application, but my application is runs word in Not-Responding mode so if i click on close
button it calls form_closing event and in that event when i check that whether document is saved or not before going to save document system throws exception. -
13. dubna 2012 6:28Moderátor
Hi CoolMayur,
Whatever you dealing with word application after you close it, it will cause the issue. So this exception is caused by design. You need to do something to avoid this.
Here are two suggestions.
1. Force the word application can’t be closed before the application close.
2. Add a Boolean value to record whether the word application is closed. If yes, avoid all code to deal with the application. Here is a sample made for you, the close boolean will be true when you close the word application.
Imports Microsoft.Office.Interop Imports Microsoft.Office.Interop.Word Public Class Form2 Dim close As Boolean = False Event DocumentBeforeClose As ApplicationEvents4_DocumentBeforeCloseEventHandler Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim app As Word.Application = New Word.Application() app.Visible = True Dim doc As Word.Document = app.Documents.Add AddHandler app.DocumentBeforeClose, AddressOf checkopen End Sub Public Sub checkopen(doc As Word.Document, ByRef cancle As Boolean) close = True End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click MessageBox.Show(close.ToString) End Sub End ClassHope this will make it more clearly.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
- Upravený Mark Liu-lxfModerator 13. dubna 2012 7:23
- Označen jako odpověď Mark Liu-lxfModerator 20. dubna 2012 7:03
-
20. dubna 2012 7:03Moderátor
Hi CoolMayur,
We haven’t heard from you for several days. I’d like to mark my reply as answer firstly. If you have any additional questions, you also can unmark the replay and post your question here.
Sorry for any inconvenience and have a nice day.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us