Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2007

Tip: Looking for answers? Try searching our database.

truly weird Word 2007 vba problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary Hillerson - 26 Jan 2007 03:18 GMT
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?
Jezebel - 26 Jan 2007 05:50 GMT
Can't comment on whether W2007 is the culprit; but PageSetup is notorious
for mysterious bugs in all versions of Word. PageSetup entails calls to the
printer driver, and the communication between Word and some printer drivers
can be problematic. Try running your code with a different printer
installed, and (if that makes a difference) check the printer manufacturer's
website for an updated driver.

Or pre-define your template so you don't need to use PageSetup at all.

> This one's a bit complicated and hard to describe, and a very weird
> problem.
[quoted text clipped - 51 lines]
>
> Any ideas?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.