Re: GRAHAM MAYOR - Re: Macro in Normal.dot prevents Word opening
- From: Fern <Fern@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 3 May 2007 16:01:01 -0700
Wow! That actually worked! I'm shocked!! THANKS GRAHAM!
I guess I'd misunderstood your website's explanation (about changing .dot to
..old) and just figured that was just a random example of how to rename the
template file so it wouldn't automatically kick in as Normal.dot when Word
opened.
Anyway... This is EXCELLENT. Not only do I have access to the macros again
but I also know that the problem is somewhere in the coding itself because
Word crashes when I try to open it after moving the 3 macros from Normal.old
into Normal.dot. Hmm, I wonder what the snag is. I just took a quick peek at
the codes and they SEEMED fine. But clearly something is still wrong.
So here's what's odd: (1) when I tried to open Word with all 3 macros in the
new Normal.dot it crashed, (2) when I tried to open it with only 1 macro at a
time in Normal.dot it crashed, BUT (3) when I copied those 1-3 macros to a
different template file (NotNormal.dot) & then tried to open Word by opening
a document formatted with NotNormal.dot, Word opened perfectly. So what does
that tell us?? I haven't a clue. I guess there's something in one or all of
the codes (& that wasn't there in the 2nd template that worked all along)
that really doesn't work well with the built in processes of Normal.dot. Hmm.
The same problem is happening when I try to open my current attempt at
writing an archiving code. It works great in any other template, but crashes
the program when I put it into Normal.
Could some good samaritan look at the code and tell me which part is
incompatible with Normal.dot?? The following is the AutoClose routine from my
most recent attempt at this archiving macro. It's supposed to check whether
the open doc is 'flagged' for archiving and, if it is, to copy it to an
archive folder. I've got a separate subroutine that can be called from the
toolbar and that's used to 'flag' the open doc & archive an instant
'snapshot' of the file without having to wait until the doc is closed. Ok, so
here's the code (& yes I know it's wordy but I like it to be intuitively
readable even months after it's written):
________________________________________________________--
Sub AutoClose()
'
Dim WSHShell, RegKey, rkeyWord, Result
Set WSHShell = CreateObject("WScript.Shell")
Dim TodaysDate As String, OldVersionPath As String, OldVersionFile As
String, OldVersionName As String
Dim NewVersionFile As String, intPos As Integer, DirExists As Boolean,
OldVersionFileNPath As String
Dim NewVersionPath As String, NewVersionFileNPath As String, fso,
MyRecentFile As RecentFile
Dim FirstTimeArchiving As Boolean
Set fso = CreateObject("Scripting.FileSystemObject")
On Error GoTo CancelledByUser
ActiveDocument.Save
FirstTimeArchiving = False
OldVersionFile = ActiveDocument.Name 'Get document name
OldVersionName = Left(OldVersionFile, Len(OldVersionFile) - 4)
'remove the file extention
Start:
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 & OldVersionName)
If rkeyWord = "" Then 'If the registry entry doesn't exist (i.e. the
file hasn't been flagged to be archived)
GoTo StopCode
Else 'if it HAS been set for archiving...
On Error GoTo CancelledByUser
OldVersionPath = ActiveDocument.Path 'Get path
OldVersionFileNPath = OldVersionPath & "\" & OldVersionFile 'Get
document's full name & path
NewVersionPath = "C:\Documents and Settings\{USER}\Word
Archive\Archived '" & OldVersionName & "'"
'Checks if an archive folder exists &, if not, makes one
If Not fso.FolderExists(NewVersionPath) Then
fso.CreateFolder (NewVersionPath)
End If
'Define the new version's filename
TodaysDate = Format((Date), "yyyy-mm-dd")
NewVersionFile = OldVersionName & " (" & TodaysDate & ").doc"
NewVersionFileNPath = NewVersionPath & "\" & NewVersionFile
'copy the current/active document to the archive location & file
name (without adding it to the 'Recent Files' list)
WordBasic.CopyFileA FileName:=OldVersionFileNPath,
Directory:=NewVersionFileNPath
If FirstTimeArchiving = True Then
MsgBox "The current version of this document has been archived.
It will now be archived whenever it's closed."
End If
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
archived.", , "Archiving Cancelled"
GoTo StopCode
StopCode:
End Sub
_________________________________________________-
So can you what might be messing with my code when it's put in Normal.dot?
Thanks for all of your help so far!! You guys have been great, especially
you Graham!!
.
- 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
- Attn: GRAHAM MAYOR - Re: Macro in Normal.dot prevents Word opening
- From: Fern
- 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
- From: Fern
- Re: GRAHAM MAYOR - Re: Macro in Normal.dot prevents Word opening
- From: Graham Mayor
- Macro in Normal.dot prevents Word from opening or debugging!
- Prev by Date: Re: Odd Behaviour with wdDialogFormatPageNumber
- Next by Date: Re: Odd Behaviour with wdDialogFormatPageNumber
- Previous by thread: Re: GRAHAM MAYOR - Re: Macro in Normal.dot prevents Word opening
- Next by thread: Re: GRAHAM MAYOR - Re: Macro in Normal.dot prevents Word opening
- Index(es):
Relevant Pages
|