Attn: GRAHAM MAYOR - Re: Macro in Normal.dot prevents Word opening
- From: Fern <Fern@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 2 May 2007 11:58:00 -0700
THANKS GRAHAM!! Great site!
I've been working through your steps for "What to do.." and am stuck at the
DOS commands. You list the following 5 locations (from your own PC)...
D:\Templates
D:\Word Startup
C:\Program Files\Microsoft Office\Office11\Startup
C:\Program Files\TechSmith\SnagIt 8
D:\My Documents
C:\Documents and Settings\Graham Mayor\Local Settings\Temp
....but then only go on to explain how to find 4 of them on OUR computers and
only seem to refer to 4 in the batch file coding. Plus you don't really
explain the inclusion of SnagIt - is that just where YOU happen to have your
default Word document folder or is that something _I_ need to have too? Or,
as I suspect, is the inclusion of "D:\My Documents" a reference to what most
people would use as their default folder? ...meaning that the 3rd & 4th items
on the DOS list are just two alternatives for the same DOS entry and that
most people would then have something like the following entry in their batch
file, instead of the SnagIt reference that you use for your PC:
REM Select default Word document folder
CD \Documents and Settings\{USER}\My Documents *** or *** CD \My Documents
DEL /A:h ~$*.dot
Does that sound right??
Thanks again for your VERY helpful website and link. I'll have to spend some
time poking around your site to see what other gems I can find :)
"Graham Mayor" wrote:
See http://www.gmayor.com/what_to_do_when_word_crashes.htm then.
http://word.mvps.org/FAQs/AppErrors/ProbsOpeningWord.htm
Reboot and try again.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Fern wrote:
That didn't work either, Jay. It looks like this ISN'T a problem with
the code itself (or at least not with anything automatic). Could Word
be finding an error elsewhere in the code (i.e. not in AutoOpen or
AutoClose) and then following the handling directions by exiting the
macro &/or crashing - all without actually/officially running the
code itself? Could the corruption be elsewhere in the .dot file,
somewhere that isn't controlled by a macro and isn't affected by
whether the file is named Normal or not??
What other likely explanations are there? I'm not familiar enough
with this type of automatic coding to really know where the trouble
is likely to be (which is probably why I bumbled into the problem in
the 1st place). Maybe I've just got to rewrite all that coding from
scratch... ... And yes I agree that it doesn't make sense to debug
the WORKING archiving code since it's actually not called until the
document closes and since it clearly doesn't contain whatever it is
that's causing so much havoc in that Normal.dot file.
Thanks for trying though.
"Jay Freedman" wrote:
Hold down the Shift key while starting Word to prevent any AutoExec,
AutoOpen or AutoNew macros from running. Then you should be able to
open the VBA editor and try to figure out what's wrong.
I haven't tried to analyze the code you posted (and an AutoClose
macro isn't going to have any effect on what happens when you try to
open a document anyway).
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
On Tue, 1 May 2007 17:35:01 -0700, Fern
<Fern@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Hi,
BACKGROUND:
Last night I wrote a code that was meant to save copies of certain
open documents to an archive folder, both when I manually tell Word
to archive and then also whenever those 'marked' documents are
closed. It was based on replies to my question about Word's
File>Versions option (which recently ate all of my file's saved
versions!) that I'd posted in another discussion group ('General
Questions': http://snipurl.com/Version). In particular, I relied a
lot on the recommended coding at
http://www.gmayor.com/save_numbered_versions.htm. And in the end, I
got the code to copy a new time/date-stamped image of the open file
to an archive folder using Sub AutoClose() and also let me save the
current version to the archive, even if I didn't want to close the
file quite yet. Since I'd also wanted to have the
archiving available to ANY file (if I chose to apply it), I put the
coding into my Normal.dot template & added some lines to check
whether a given file had had archiving enabled - if not, the file
SHOULD have opened & closed as usual - but if so, then it should
have let me save to the archive at any point while the file was
open.
PROBLEM:
Well, the code worked GREAT when I was testing it last night
(=opening & closing documents, but never closing Word itself) but
today, when I tried to open new or existing documents that are
based on the Normal.dot template, Word immediately encountered a
problem, sent up a nondescript error message, and shut itself down.
So not only can I not debug the code at this point, but I can't
even open the .dot file independently of Word in order to remove
the archiving code without deleting the whole template.
Luckily I happened to have written part of the Normal code into
another template and, when I open documents based on that template,
they work just fine - as did the archiving code in the 2nd
template's AutoClose() macro. So I know the archiving itself works
a-ok (thank goodness). And so clearly the trouble is coming from
one of the additional codes that I added to the Normal template:
(1) code that lets users archive their file immediately & without
closing it, and that will 'mark' the open file as one that needs to
be archived if it's never been archived before (by adding an entry
{called 'RegKey' - see below} to the registry), OR (2) code that
tells the user whether the open document has archiving enabled
(based whether there's a RegKey entry for that file in the
Registry).
MY BEST GUESS:
So, my big worry is that I may have stupidly put one of the codes
into an AutoOpen() subroutine for some reason and that the error
handling is just redirecting Word to exit the macro as soon as it
hits a problem - meaning that it can't open anything and so has to
shut itself down.
HELP NEEDED:
If that's the case, do I have any way to get into that .dot
template file to debug it?? Is there some other program or method
to access its macros without running them (especially if this is
caused by a buggy AutoOpen)?? Or is my only option to delete the
flawed Normal template and let Word build a new one, without all my
settings & styles or archiving code??
And if I have to start from scratch again, can anyone tell me how I
might adapt the code below (which is from the WORKING 2nd template,
NOT Normal.dot) so I can at least call it from one of the
toolbars/buttons and can 'mark' files for archiving that way??
I'd be SO grateful for any help you can give me. I just don't know
how to get myself out of this catch-22.
Thank you!!
THE WORKING TEMPLATE CODE:
Sub AutoClose()
'Saves a numbered copy of the current file to an archive location
'
Dim WSHShell, RegKey, rkeyWord, Result
Set WSHShell = CreateObject("WScript.Shell")
Dim iCount As Integer, StrDate As String, StrPath As String,
StrFile As String, StrName As String
Dim StrVersionFile As String, intPos As Integer, DirExists As
Boolean, StrFileNPath As String
Dim NewStrPath As String, StrVersionFileNPath As String, fso,
MyRecentFile As RecentFile
Set fso = CreateObject("Scripting.FileSystemObject")
ActiveDocument.Save 'Ensures the saved doc is the most up to
date version
StrFile = ActiveDocument.Name 'Get document name
StrName = Left(StrFile, Len(StrFile) - 4) 'remove the file
extention RegKey =
"HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Settings\" On
Error Resume Next 'No entry in registry will flag an error
rkeyWord = WSHShell.RegRead(RegKey & StrName) If Not rkeyWord =
"" Then 'If the registry entry DOES exist (i.e. the file has
already been marked for archiving) StrDate = Format((Date),
"yyyy-mm-dd") intPos = InStrRev(StrFile, ".doc") 'Look at
that name for an
extension
If intPos = 0 Then 'If document is not saved
On Error GoTo CancelledByUser
'ActiveDocument.Save 'Save it
End If
StrPath = ActiveDocument.Path 'Get path
StrFileNPath = StrPath & "\" & StrFile 'Get document's
full name & path
intPos = InStrRev(StrFile, " - Version") 'Mark the
version number If intPos = 0 Then 'No version number
intPos = InStrRev(StrFile, ".doc") 'Mark the
extension instead End If
StrFile = Left(StrFile, intPos - 1) 'Strip the extension
or version number
Start: 'Get Registry Data
RegKey =
"HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Settings\"
On Error Resume Next 'No entry in registry will flag an
error rkeyWord = WSHShell.RegRead(RegKey & StrFile) If
rkeyWord = "" Then 'Registry entry does not exist
WSHShell.regwrite RegKey & StrFile, 0 'So create it
GoTo Start: End If
iCount = Val(rkeyWord) + 1 'Increment number
WSHShell.regwrite RegKey & StrFile, iCount 'And write it
to the registry
NewStrPath = "C:\Documents and Settings\{USER}\Word
Archive\Archived '" & StrFile & "'"
'Checks if an archive folder exists &, if not, makes one
If Not fso.FolderExists(NewStrPath) Then
fso.CreateFolder (NewStrPath)
End If
'Define the new version's filename
StrVersionFile = StrFile & " (" & StrDate & "@" &
Format((Time), "Hh.Nn") & ").doc"
StrVersionFileNPath = NewStrPath & "\" & StrVersionFile
'copy the current/active document to the archive location &
file name (without adding it to the 'Recent Files' list)
WordBasic.CopyFileA FileName:=StrFileNPath,
Directory:=StrVersionFileNPath
End If
GoTo StopCode
CancelledByUser: 'Trap the pressing of the Cancel button
MsgBox "There was a problem running the code & this file
version wasn't saved or closed.", , "Archiving Cancelled"
GoTo StopCode
StopCode:
End Sub
- Follow-Ups:
- Re: GRAHAM MAYOR - Re: Macro in Normal.dot prevents Word opening
- From: Graham Mayor
- Re: GRAHAM MAYOR - Re: Macro in Normal.dot prevents Word opening
- References:
- Macro in Normal.dot prevents Word from opening or debugging!
- From: Fern
- Re: Macro in Normal.dot prevents Word from opening or debugging!
- From: Jay Freedman
- Re: Macro in Normal.dot prevents Word from opening or debugging!
- From: Fern
- Re: Macro in Normal.dot prevents Word from opening or debugging!
- From: Graham Mayor
- Macro in Normal.dot prevents Word from opening or debugging!
- Prev by Date: Re: paragraph numbering
- Next by Date: Re: Assigning non listed command for customize keyboard
- Previous by thread: Re: Macro in Normal.dot prevents Word from opening or debugging!
- Next by thread: Re: GRAHAM MAYOR - Re: Macro in Normal.dot prevents Word opening
- Index(es):
Loading