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 / February 2007

Tip: Looking for answers? Try searching our database.

Template Macro runs fine but fails on opening as a document.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brendan - 28 Feb 2007 01:48 GMT
I have a template that has the below code (which is identical) and runs
either on a New document from the template or after the document has been
saved and then opened at a later date.   If I open the doucment from FILE,
NEW, Templates on My Computer, and select the "Create New" - Template Radio
button (bottom right of templates tabs), then I get no error.  However, if I
select the "Document" radio button in the bottom right, the document errors
out with the Error 91 Code and the "Object Variable....Not set.  Here is the
code:

Sub AutoNew()
ActiveWindow.ActivePane.DisplayRulers = True 'display the rulers
ActiveWindow.ActivePane.View.ShowAll = False 'turn off the formatting
command view
With ActiveWindow.View
  .Type = wdPrintView 'select page/print layout view
'Alternative to the above line if normal view is preferred
 '.Type = wdNormalView
  .Zoom.Percentage = 100 'set the display zoom to 100%
  .FieldShading = wdFieldShadingWhenSelected 'set the field shading
preference
  .ShowFieldCodes = False 'turn off field code display
  .DisplayPageBoundaries = True 'Turn on white space between pages
End With
'CommandBars("Reviewing").Visible = False 'Turn off the reviewing toolbar

   Message = "Just Start Typing and TAB to next field - New"
   Title = "Sales Widget Instructions"    ' Define title.
   Response = MsgBox(Message, vbOKOnly, Title)
   ActiveDocument.Bookmarks("swNumber").Select
   ActiveDocument.Sections(2).ProtectedForForms = False
   ActiveDocument.Sections(3).ProtectedForForms = False
End Sub
-------------------------------------------------------------------------------------
Private Sub Document_Open()
ActiveWindow.ActivePane.DisplayRulers = True 'display the rulers
ActiveWindow.ActivePane.View.ShowAll = False 'turn off the formatting
command view
With ActiveWindow.View
  .Type = wdPrintView 'select page/print layout view
'Alternative to the above line if normal view is preferred
 '.Type = wdNormalView
  .Zoom.Percentage = 100 'set the display zoom to 100%
  .FieldShading = wdFieldShadingWhenSelected 'set the field shading
preference
  .ShowFieldCodes = False 'turn off field code display
  .DisplayPageBoundaries = True 'Turn on white space between pages
End With
'CommandBars("Reviewing").Visible = False 'Turn off the reviewing toolbar

   Message = "Welcome Back!"
   Title = "Sales Widget Instructions"    ' Define title.
   Response = MsgBox(Message, vbOKOnly, Title)
   ActiveDocument.Bookmarks("swNumber").Select
   ActiveDocument.Sections(2).ProtectedForForms = False
   ActiveDocument.Sections(3).ProtectedForForms = False
End Sub
Jezebel - 28 Feb 2007 03:37 GMT
What line gives the error?

>I have a template that has the below code (which is identical) and runs
> either on a New document from the template or after the document has been
[quoted text clipped - 56 lines]
>    ActiveDocument.Sections(3).ProtectedForForms = False
> End Sub
Brendan - 28 Feb 2007 04:58 GMT
I believe it is the: ActiveWindow.ActivePane.View.ShowAll = False 'turn off
the formatting

We upgraded from Office 2000 to Office 2003 XP and the form worked fine
before the upgrade.

> What line gives the error?
>
[quoted text clipped - 58 lines]
> >    ActiveDocument.Sections(3).ProtectedForForms = False
> > End Sub
Jezebel - 28 Feb 2007 05:15 GMT
Try stepping through the code (click anywhere inside the macro, then press
F8 once for each instruction) to find *exactly* which line. There's nothing
obviously wrong with the line you mention.

>I believe it is the: ActiveWindow.ActivePane.View.ShowAll = False 'turn off
> the formatting
[quoted text clipped - 70 lines]
>> >    ActiveDocument.Sections(3).ProtectedForForms = False
>> > End Sub
Brendan - 28 Feb 2007 15:50 GMT
The code vomits on:

ActiveWindow.ActivePane.DisplayRulers = True 'display the rulers

> Try stepping through the code (click anywhere inside the macro, then press
> F8 once for each instruction) to find *exactly* which line. There's nothing
[quoted text clipped - 74 lines]
> >> >    ActiveDocument.Sections(3).ProtectedForForms = False
> >> > End Sub
Brendan - 28 Feb 2007 23:55 GMT
It does not like the WITH line statement at all.  If I remove all of the
lines for that particular paragraph, the code then works.  I just can't
figure out what is wrong with it because it used to work fine.

> Try stepping through the code (click anywhere inside the macro, then press
> F8 once for each instruction) to find *exactly* which line. There's nothing
[quoted text clipped - 74 lines]
> >> >    ActiveDocument.Sections(3).ProtectedForForms = False
> >> > End Sub
 
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.