Run time error 91

S

Sammy

Hello,

I get a Run-time error "91" - Object variable or with block varialbe not set
message on this macro:

Sub tryit()
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryHeader
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.TypeText Text:="mytagline"
Selection.Range.InsertAutoText
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub


It errors on this line:

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

Any clues? Thanks!
 
S

Sammy

One thought, is there a better way of inserting an autotext into a Primary
header (remember that when you create the template you only have one page so
there's no primary header) rather than my steps of actually creating a new
page and then viewing the header, etc.? thanks
 
T

Tony Jollans

Yes there is a better way. Assuming you know where (in which template) the
AutoText is you can use something like:

Templates("Your Template").AutoTextEntries("Your AutoText").Insert _
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range, True

If you don't know where it is you will need to type the text as you show,
but you can still use the Range of the Header as per the above code.
 
S

Sammy

Thanks - that worked great!

Tony Jollans said:
Yes there is a better way. Assuming you know where (in which template) the
AutoText is you can use something like:

Templates("Your Template").AutoTextEntries("Your AutoText").Insert _
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range, True

If you don't know where it is you will need to type the text as you show,
but you can still use the Range of the Header as per the above code.

--
Enjoy,
Tony

www.WordArticles.com
 

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