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

B

Brendan

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
 
B

Brendan

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.
 
J

Jezebel

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.
 
B

Brendan

The code vomits on:

ActiveWindow.ActivePane.DisplayRulers = True 'display the rulers
 
B

Brendan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top