View Single Post
  #8   Report Post  
Posted to microsoft.public.word.newusers
John... Visio MVP John... Visio MVP is offline
external usenet poster
 
Posts: 33
Default Newbie macro help please

I am not sure what is going on but
Debug.Print ActiveDocument.AttachedTemplate.BuildingBlockEntri es.Count
results in a value of zero.


From another thread, it appears, according to Graham Mayor, the macro
recorder makes a mess of Autotext entries

:Word 2007 stores autotext entries differently from earlier versions and the
:macro recorder does not record entries that are stored in
:buildingblocks.dotx. In fact the macro recorder makes a complete hash of
:recording anything to do with autotext entries. You will have to modify the
:code by hand
:
:If your macro crashes on the line
:
:ActiveDocument.AttachedTemplate.BuildingBlockEntr ies("Plain Number 1"). _
:Insert Whe=Selection.Range, RichText:=True
:
then the entry is not stored in the document template where the line is
:looking for it.
:
:Either use the BuildingBlocks Organizer to move it to the document template
r
:to normal.dot and then use
:
:NormalTemplate.BuildingBlockEntries("Plain Number 1").Insert
:Whe=Selection.Range, _
:RichText:=True


Unfortunately, I have been unable to get the NormalTemplate to work. I still
end up with a count of zero.

John... Visio MVP

"Barnet" wrote in message
...
Hi John,

Thanks so much, we're getting close. Let me show you what the debug window
displays:

WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntri es(" Blank").Insert _
Whe=Selection.Range, RichText:=True
WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntri es("Plain Number 2").
_
Insert Whe=Selection.Range, RichText:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

Now, I know absolutely zippo about Visual Basic. I have noticed that it
seems to want to put "Plain Number 2" in, whereas I'd think it would want
to
insert the symbol for successive page numbers (whatever that would be).

I have tried to create this macro both by going straight to the page
number
tab, and also by first opening a footer, selecting "blank", and then using
the page number tab. I then have to use the Exit Footer (or whatever it's
called) button to get back to the main document.

But no matter what I try it ends up with the error messages above.

Thanks for taking the time with my question, I appreciate it.

Barnet

"John... Visio MVP" wrote:

"Barnet" wrote in message
...
I'm trying to record a macro that will number the pages in my document.
I
seem to do OK at first: name the macro, make a keyboard shortcut, begin
recording, execute the commands to put page numbers at the bottom
center
of
the document, and then stop recording.

But when I run the macro it stops with 'Runtime error 5941, the
requested
member of the collection does not exist.' When I look at debug, it
seems
to
show all the steps except for adding the page number itself down in the
footer.

Also, since I've tried this a few times I seem to have to come up with
new
names for the macro. Is there a way to erase all the old attempts and
old
names to 'clear the slate'?

Thanks in advance,

Barnet



Your error was due to a line like
ActiveDocument.AttachedTemplate.BuildingBlockEntri es("Pg. Number
1").Insert Whe=Selection.Range, RichText:=True

I am not sure why, but it may be a matter of context.

You should be aware, that what the macro recorder records is not always
great code and there may be issues with replaying the macros. With the
Headers/Footers you need to switch windows between the main window and
the
H/F window and that may be an issue.

John... Visio MVP