Repressing Word alerts?

J

joniba

Hi all,
I'm developing an application that reads downloaded .doc files from the
filesystem. Occasionally one of these files, when attempting to open with
word, cause it to crash. This leads to 2 situations in which I get alerts:

1.When word crashes and asks what to do (alert asks if to send error report
and if to restart word?)
2.If I try opening the file again at a later time (alert asks if I really
want to open this file, which causes "serious damage" last time it was opened)

I would like to know if I can somehow repress these alerts, preferrably by
giving them predetermined answers.

I am using VS2008 with framework 3.5 (though I don't think that makes much
of a difference), and am working with the Microsoft office Primary Interop
Assembly (path ends in Visual Studio Tools for
Office\PIA\Office12\Microsoft.Office.Interop.Word.dll). I'm working in a
class library.
 
J

Jean-Guy Marcil

joniba said:
Hi all,
I'm developing an application that reads downloaded .doc files from the
filesystem. Occasionally one of these files, when attempting to open with
word, cause it to crash. This leads to 2 situations in which I get alerts:

1.When word crashes and asks what to do (alert asks if to send error report
and if to restart word?)

I believe that this is a Windows alert, so no VBA (or methods from the Word
object library) will be able to suppress that.
2.If I try opening the file again at a later time (alert asks if I really
want to open this file, which causes "serious damage" last time it was opened)

Again, I do not believe you can suppress that.
I would like to know if I can somehow repress these alerts, preferrably by
giving them predetermined answers.

I am using VS2008 with framework 3.5 (though I don't think that makes much
of a difference), and am working with the Microsoft office Primary Interop
Assembly (path ends in Visual Studio Tools for
Office\PIA\Office12\Microsoft.Office.Interop.Word.dll). I'm working in a
class library.

I believe you are asking the wrong question... You should be investigating
why Word crashes some times, and prevent the crash from occuring in the first
place. It may be more work, but it will prove more beneficial in the long
run...
 
J

joniba

It is true what you say, but I wouldn't even know where to start. These
documents are downloaded from a government website and are all .doc files
that have been saved in html format. From my own comparison of the files
that cause word to crash with the ones that don't, nothing stands out about
them.

Do you know of any way I can find out why these documents cause errors?
 
J

Jean-Guy Marcil

joniba said:
It is true what you say, but I wouldn't even know where to start. These
documents are downloaded from a government website and are all .doc files
that have been saved in html format. From my own comparison of the files

You are converting doc files into HTML ones, and then running some code on
the HTML files?
Why?
Why don't you work with the doc files directly?
that cause word to crash with the ones that don't, nothing stands out about
them.

Do you know of any way I can find out why these documents cause errors?

Will a given file that causes Word to crash consitently make Word crash?
If so, you should debug the code step by step and try to pin down either the
line of code that makes Word crash or the environmental factor(s) that make
Word crash (Working in a table, with pictures, in headers, etc.).
 
J

joniba

Hi Jean-Guy,
The files I am working with are downloaded from a government website.
They are all .html files. But their format is of a .doc file that has been
saved in word as web pages. That is to say, presumably this government
website saves their documents as html files and offers the .htmls for
download. As far as I know, there is no way for me to get to the .doc files
on this website.


When you say "debug the code step by step", what are you referring to? Yes,
these documents will always cause Word to crash. When it crashes, it asks
you if you want to debug, but doing so simply causes another crash. But I
have never debugged a Word document, perhaps there is a procedure involved
that I don't know about?
 
J

Jean-Guy Marcil

joniba said:
Hi Jean-Guy,
The files I am working with are downloaded from a government website.
They are all .html files. But their format is of a .doc file that has been
saved in word as web pages. That is to say, presumably this government
website saves their documents as html files and offers the .htmls for
download. As far as I know, there is no way for me to get to the .doc files
on this website.

Do you/have you tried re-converting the files back to a doc format before
running the code?
When you say "debug the code step by step", what are you referring to? Yes,
these documents will always cause Word to crash. When it crashes, it asks
you if you want to debug, but doing so simply causes another crash. But I
have never debugged a Word document, perhaps there is a procedure involved
that I don't know about?

Start the code from he VBA editor window. Place the cursor inside the sub
you want to run, hit F8 to execute the code line by line. Whenever it
crashes, the last line you executed will give you a clue as to why it crashes.

If you have a lot of code, put a "Stop" command halfway through the code. If
it crashes before stopping, you will know the problem is in the first half of
the code. Next, put the Stop command 25% of the way down the code (or 75%
depending on the result with the stop half way in the code). etc.
 
J

joniba

Jean-Guy Marcil said:
Do you/have you tried re-converting the files back to a doc format before
running the code?

How would I do that? Word cannot open these files...
Start the code from he VBA editor window. Place the cursor inside the sub
you want to run, hit F8 to execute the code line by line. Whenever it
crashes, the last line you executed will give you a clue as to why it crashes.

If you have a lot of code, put a "Stop" command halfway through the code. If
it crashes before stopping, you will know the problem is in the first half of
the code. Next, put the Stop command 25% of the way down the code (or 75%
depending on the result with the stop half way in the code). etc.

What does "Start the code from he VBA editor window" mean? As far as I can
tell from the VBA editor, there is no option to open a file from the editor.
So what code am I supposed to start? All I have is this html file, and
running the debugger when prompted by word when it crashes only leads to
another crash...
I'm afraid that I am a .NET programmer and am posting in this forum merely
because I have gotten no answers in any non-VBA forums. So a very brief
explanation of how to do this would be very appreciated.
 
J

Jean-Guy Marcil

joniba said:
How would I do that? Word cannot open these files...

???
All along this thread I was under the impression that the crashes you had
were occuring at some point while running the code on the said files.

Now, I see that you cannot even open the files... You mean that after
downloading them, you cannot even open them, even if you try manually?

If so, then of course, the code will crash on those.

I think you need to take a step back here and describe exactly how you get
those files.
Are they websites you ave saved as HTML files (before running the code on
them) or actual files you downloaded and then trying to process (after
manually dowloading them)? Or, is your code actually doing the "Save As" on a
web page and then trying to process the resulting file?
 
J

joniba

Jean-Guy,
As I said, these are files that have been directly posted by a government
website for the purpose of being downloaded. Word crashes when trying to
open them before I have made any modifications to them.
The only explanation I can think of now is that there is a difference in
the way different versions of Word create html files.
But if you remember my original question, it was how to get around the
alerts thrown by word when it crashes, not how to get around the crashes,
which seems quite beyond me.
 
J

Jean-Guy Marcil

joniba said:
Jean-Guy,
As I said, these are files that have been directly posted by a government
website for the purpose of being downloaded. Word crashes when trying to
open them before I have made any modifications to them.
The only explanation I can think of now is that there is a difference in
the way different versions of Word create html files.
But if you remember my original question, it was how to get around the
alerts thrown by word when it crashes, not how to get around the crashes,
which seems quite beyond me.

Yes, I remember your original question, but, again, you cannot go around
that message.

This is why I went down the path of finding out what causes it to appear.

I do not unerstand why would somoene make an HTML file available for
download... Normally, you use an HTML page to download files in other formats
like doc, pdf, jpg, xls, etc. I have never seen a link on a Web page that
provides a download of an HTML page. Very weird!

Sorry I cannot be more helpful beyond repeating that you have to somehow
convert those files from HTML to doc before processing them with VBA. This
might be a little tricky because very often HTML files contains link to
content outside of the file... The file does not necessarily actually have
the actual content. These links may be what is causing you grief when you try
to open them.
 
J

joniba

Well, this response is somewhat delayed I know.
Anyway, technically, I think you are right. These html files are actually
meant to be viewed, not downloaded, though I am not 100% sure about that.

But most importantly, I found the solution, for anyone else who may be
interested. The solution was to install Service Pack 2 for Office. None of
these issued have recurred since I've done that.

Thanks again for the help, it's much appreciated.
 

Ask a Question

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.

Ask a Question

Top