G
Gary Hillerson
This one's a bit complicated and hard to describe, and a very weird
problem.
I have a template -- call it MyTemplate -- that, at creation time
(AutoNew), allows the user to specify various initial content and
formatting options, and then "sets up" the document according to those
options.
The code does this:
1. AutoNew does some initialization, then opens the DocSetup dialog
2. DocSetup presents options to the user, then calls the
InsertDocumentPages function
3. InsertDocumentPages sets the margins, and inserts some content into
the document (various pages and text)
This code has been working fine since 2000, and continues to work just
fine in Word 2003 and earlier versions.
However, under very specific circumstance, the code fails in Word
2007, with InsertDocumentPages throwing an error.
1. I open any Word document (not based on MyTemplate), call it
Document1
2. I create a document based on MyTemplate (docA)
3. I close docA
4. I open another document based on MyTemplate (docB)
In docB, when my dialog code calls InsertDocumentPages, it throws an
error 6051 "macro cannot be found or has been disabled because of your
Macro security settings". What makes it even weirder is that I
modified my dialog code to effectively say "If InsertDocumentPages
threw an error, then call it again" and that call always works.
When I trace what's happening, the error is thrown in this code
Application.ScreenUpdating = False
With ActiveDocument.PageSetup
.LeftMargin = 108
.RightMargin = 72
.TopMargin = 72
.BottomMargin = 72
End With
This happens whether tell Word to allow all macros, or to only allow
signed code (my code is signed).
It only happens if I
a) have a Word doc open that's not based on my template
b) close the last opened doc that's based on my template (i can open
dozens, and this doesn't happen until i close the last one)
c) open another doc based on my template.
I'm hoping this is some sort of Word 2007 Beta problem with digital
certificates or macro storage, but it's pretty darn perplexing.
Any ideas?
problem.
I have a template -- call it MyTemplate -- that, at creation time
(AutoNew), allows the user to specify various initial content and
formatting options, and then "sets up" the document according to those
options.
The code does this:
1. AutoNew does some initialization, then opens the DocSetup dialog
2. DocSetup presents options to the user, then calls the
InsertDocumentPages function
3. InsertDocumentPages sets the margins, and inserts some content into
the document (various pages and text)
This code has been working fine since 2000, and continues to work just
fine in Word 2003 and earlier versions.
However, under very specific circumstance, the code fails in Word
2007, with InsertDocumentPages throwing an error.
1. I open any Word document (not based on MyTemplate), call it
Document1
2. I create a document based on MyTemplate (docA)
3. I close docA
4. I open another document based on MyTemplate (docB)
In docB, when my dialog code calls InsertDocumentPages, it throws an
error 6051 "macro cannot be found or has been disabled because of your
Macro security settings". What makes it even weirder is that I
modified my dialog code to effectively say "If InsertDocumentPages
threw an error, then call it again" and that call always works.
When I trace what's happening, the error is thrown in this code
Application.ScreenUpdating = False
With ActiveDocument.PageSetup
.LeftMargin = 108
.RightMargin = 72
.TopMargin = 72
.BottomMargin = 72
End With
This happens whether tell Word to allow all macros, or to only allow
signed code (my code is signed).
It only happens if I
a) have a Word doc open that's not based on my template
b) close the last opened doc that's based on my template (i can open
dozens, and this doesn't happen until i close the last one)
c) open another doc based on my template.
I'm hoping this is some sort of Word 2007 Beta problem with digital
certificates or macro storage, but it's pretty darn perplexing.
Any ideas?