AutoTextEntries("Page X of Y") does not work on Word 2007

K

Kim

Hi,

While testing my vba script on word 2007, I found that autotextentries "x of
y" does not work. The source code is like this:

With RptDoc.Sections(1)
With .Footers(wdHeaderFooterPrimary)
.Range.Select
.Range.Borders(wdBorderTop).Visible = True
.Range.Font.Size = 10
.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeText Text:="Footer "
NormalTemplate.AutoTextEntries("Page X of Y").Insert
Where:=Selection.Range
End With

' Close the footer pane
While ActiveWindow.View.SplitSpecial <> wdPaneNone
ActiveWindow.Panes(2).Close
Wend
End With

The script runs fine on word 2003 and I can see the Page X of Y in the
footer. If I run the same script on word 2007, the script does not raise any
errors but where Page X of Y should appear is blank.

Would you let me know if I should update any parts of my vba script for word
2007? Is "NormalTemplate.AutoTextEntries("Page X of Y").Insert
Where:=Selection.Range" no longer valid in word 2007?


Thank you in advance,

-- mk
 
J

Jay Freedman

You have a lot of work to do. :-(

In Word 2007, AutoText entries are a specific group of the more general Building
Blocks collection. You can't access any template's .AutoTextEntries collection
the way you could in 2003. Start by reading the topic in the Word 2007 VBA Help
titled "Working with Building Blocks".

Now you need to know (a) which template contains the entry, typically
Normal.dotm or Building Blocks.dotx, but it could be any other template; (b)
which category it's in, typically "General"; and (c) its name. For your example,
the code would be

NormalTemplate.BuildingBlockTypes(wdTypeAutoText).Categories( _
"General").BuildingBlocks("Page X of Y").Insert Where:=Selection.Range

The next hurdle is that the default Normal.dotm in Word 2007 doesn't contain
_any_ AutoText entries, particularly this one. You would have to prepare the
template for use by creating the entry, and any others that you expect to find.
 
N

Nan

Hi Kim,

I have the same situation , can you please let me know how you updated the
script to work for both word 2003 and 2007.

Thanks in advance,
Nan
 

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