473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

VB.NET and Microsoft Word problem: topic becomes read-only

I am opening a Word document with code like this:

Dim WordApp As New Word.Application
Try
WordApp.Documents.Open(CType("C:\Temp\mydoc.doc", Object))
etc. -- etc. -- etc.
Return True
Catch ex As Exception
Return False
Finally
Try
WordApp.Documents.Close()
WordApp.Quit()
Catch ex As Exception
End Try
End Try

This code works fine unless I crash somewhere in the etc part of the code
and the Finally never triggers properly. In this case, the file becomes
locked in a read-only mode. I can't delete it, edit it, or rename it
regardless of what I try short of rebooting. The only way I can get it
released is to reboot. Is there something that can be done to get it
unlocked without rebooting?
Aug 13 '06 #1
3 1404
Hi

Is it possible to deal with it in your exception handling code
(assuming this gets called ok if the code 'crashes')? I.e. Close the
document and Word if an exception is caught?

Just an idea

Thanks
Martin
genojoe wrote:
I am opening a Word document with code like this:

Dim WordApp As New Word.Application
Try
WordApp.Documents.Open(CType("C:\Temp\mydoc.doc", Object))
etc. -- etc. -- etc.
Return True
Catch ex As Exception
Return False
Finally
Try
WordApp.Documents.Close()
WordApp.Quit()
Catch ex As Exception
End Try
End Try

This code works fine unless I crash somewhere in the etc part of the code
and the Finally never triggers properly. In this case, the file becomes
locked in a read-only mode. I can't delete it, edit it, or rename it
regardless of what I try short of rebooting. The only way I can get it
released is to reboot. Is there something that can be done to get it
unlocked without rebooting?
Aug 14 '06 #2
Right now, this is a problem during debugging. If I stop debugging somewhere
during the etc, etc, etc. I am stuck rebooting to get rid of my test file.
I was hoping for a way to avoid rebooting.

If I could only remember not to stop the debugging until after executing the
Finally........ That's another story. My memory for details like that
sucks. I suspect after a few reboots, my memory will suddenly get better.

In run time, I suspect your suggestion would work. Also, knowledge of how
to recover from such a file might prove useful sometime in the future. It
seems there should be a way to kill an orphan Word file like that without a
reboot.

"Pritcham" wrote:
Hi

Is it possible to deal with it in your exception handling code
(assuming this gets called ok if the code 'crashes')? I.e. Close the
document and Word if an exception is caught?

Just an idea

Thanks
Martin
Aug 14 '06 #3
Hi

Have you checked the running processes in Task Manager to see if
instance of Word that you fired up is still there - it may well be (as
it hasn't been shut down) and if that's the case, that ('hidden'
instance of Word) may be the reason that the file is locked as it's
already being modified.

Just an idea

Cheers
Martin
genojoe wrote:
Right now, this is a problem during debugging. If I stop debugging somewhere
during the etc, etc, etc. I am stuck rebooting to get rid of my test file.
I was hoping for a way to avoid rebooting.

If I could only remember not to stop the debugging until after executing the
Finally........ That's another story. My memory for details like that
sucks. I suspect after a few reboots, my memory will suddenly get better.

In run time, I suspect your suggestion would work. Also, knowledge of how
to recover from such a file might prove useful sometime in the future. It
seems there should be a way to kill an orphan Word file like that without a
reboot.

"Pritcham" wrote:
Hi

Is it possible to deal with it in your exception handling code
(assuming this gets called ok if the code 'crashes')? I.e. Close the
document and Word if an exception is caught?

Just an idea

Thanks
Martin
Aug 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Erickson | last post by:
I need to read some (about 15,000) word documents and add some wrappers around them for importing into a database. What is the best way to read a ..doc file in VB? I would like to save the...
476
by: Xah Lee | last post by:
Microsoft Hatred, FAQ Xah Lee, 20020518 Question: U.S. Judges are not morons, and quite a few others are not morons. They find MS guilty, so it must be true. Answer: so did the German...
11
by: name | last post by:
Here is a first attempt at a line/word wrapping utility. Seems to work okay, but lacks some checking stuff, etc. --------------------------------------------------------- #include <stdio.h>...
5
by: Niklas Uhlin | last post by:
Someone please explain why Session_Start fires multiple times / retains SessionID values between sessions, when you open an ASP.NET page from MS Word. For details of the problem, see below: 1....
2
by: William LaMartin | last post by:
I have created a program that allows for the automation of things in Word documents, like changing the values of DocVariables and the links to Excel Sheets. I did it using interoperoperatability,...
2
by: Mux | last post by:
I am facing the following problem while exporting data to Word. The current implementation is as described below: I have a JSP file which has a link that enables you to export the data to Word....
1
by: Alan T | last post by:
I am working and tried to start and read an article from MS: http://support.microsoft.com/kb/301659 I followed the step to add reference to my dummy application, Microsoft Word 11.0 Object...
7
by: FFMG | last post by:
Hi, I have a form that allows users to comment, add entries and so on. But what a lot of them do is copy and paste directly from MS Word to my forms. almost all browsers will accept the post...
4
by: Kelii | last post by:
Access 2003, Windows XP SP2 I have an application that generates a word document populated with a variety of fields from Access tables. The word document is generated when the user presses a...
2
by: whodgson | last post by:
The following code accepts a string from the user and swaps the first and last letters in each word. It prints out the original string incorrectly by dropping off the first letter of the first word....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.