Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
Barnet Barnet is offline
external usenet poster
 
Posts: 26
Default Newbie macro help please

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
  #2   Report Post  
Posted to microsoft.public.word.newusers
Terry Farrell Terry Farrell is offline
external usenet poster
 
Posts: 2,904
Default Newbie macro help please

Tools, Macros, select and Delete.

--
Terry Farrell - MSWord MVP

"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


  #3   Report Post  
Posted to microsoft.public.word.newusers
Suzanne S. Barnhill Suzanne S. Barnhill is offline
external usenet poster
 
Posts: 33,624
Default Newbie macro help please

Note that this should not require a macro. Just View | Header and Footer,
Switch Between Header and Footer, Ctrl+E to center (or tab once to the
centered tab stop), click on Insert Page Number, and all your pages will be
numbered. Save the document as a template if desired.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

"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



  #4   Report Post  
Posted to microsoft.public.word.newusers
Barnet Barnet is offline
external usenet poster
 
Posts: 26
Default Newbie macro help please

Thanks Terry and Suzanne,

I should say that I use MS Word 2007, so I don't have the Tools etc. pathway
to go. I found the dialogue that allowed me to erase previous attempts at
making macros, so that's good.

Suzanne, to be clear, I use the standard way of doing page numbers that
involves clicking on the Insert tab, then page numbering, then waiting while
the options load, then selecting bottom center, my consistent choice. I just
want to automate the process, so while your suggestion makes sense it doesn't
really save me the clicks. OTOH, the notion of creating a template makes
sense.

However, I'd still like to find out why I'm having trouble recording this
simple macro, since I'd probably make some other ones to automate certain
common tasks. That's the reason for macros, right?

So if someone still might help me figure out what's going wrong with my
current attempt I'd be very grateful.

Barnet
  #5   Report Post  
Posted to microsoft.public.word.newusers
Terry Farrell Terry Farrell is offline
external usenet poster
 
Posts: 2,904
Default Newbie macro help please

In Word 2007, the Macro button is on the Developer tab on the Ribbon. But
you need to enable the Developer Tab under Word Options, Popular Tab.

Terry

"Barnet" wrote in message
...
Thanks Terry and Suzanne,

I should say that I use MS Word 2007, so I don't have the Tools etc.
pathway
to go. I found the dialogue that allowed me to erase previous attempts at
making macros, so that's good.

Suzanne, to be clear, I use the standard way of doing page numbers that
involves clicking on the Insert tab, then page numbering, then waiting
while
the options load, then selecting bottom center, my consistent choice. I
just
want to automate the process, so while your suggestion makes sense it
doesn't
really save me the clicks. OTOH, the notion of creating a template makes
sense.

However, I'd still like to find out why I'm having trouble recording this
simple macro, since I'd probably make some other ones to automate certain
common tasks. That's the reason for macros, right?

So if someone still might help me figure out what's going wrong with my
current attempt I'd be very grateful.

Barnet




  #6   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

"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

  #7   Report Post  
Posted to microsoft.public.word.newusers
Barnet Barnet is offline
external usenet poster
 
Posts: 26
Default Newbie macro help please

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


  #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




  #9   Report Post  
Posted to microsoft.public.word.newusers
Barnet Barnet is offline
external usenet poster
 
Posts: 26
Default Newbie macro help please

Hi John,

To the extent I understand your post, it seems as if I'm stuck.

The somewhat odd thing is that the macro recorder seems to reach for
AutoText or BuildingBlocks, if that's similar. Is that where the page numbers
used by the Insert Page Number tab live?

Anyway, I guess that's the end of the road on this one. Seems very strange
that something seemingly so simple crashes.

Thanks again,

Barnet

"John... Visio MVP" wrote:

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





  #10   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

It is possible, but I think someone like Graham Mayor or Greg Maxek know the
workaround.

John..

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

To the extent I understand your post, it seems as if I'm stuck.

The somewhat odd thing is that the macro recorder seems to reach for
AutoText or BuildingBlocks, if that's similar. Is that where the page
numbers
used by the Insert Page Number tab live?

Anyway, I guess that's the end of the road on this one. Seems very strange
that something seemingly so simple crashes.

Thanks again,

Barnet

"John... Visio MVP" wrote:

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









  #11   Report Post  
Posted to microsoft.public.word.newusers
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Newbie macro help please

Use:

Dim prange As Range
With ActiveDocument
Set prange = .Sections(1).Footers(wdHeaderFooterPrimary).Range
.Fields.Add Range:=prange, Type:=wdFieldEmpty, Text:="page"
prange.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With

If you want the page number on the right, replace wdAlignParagraphCenter
with wdAlignParagraphRight, similarly for left.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

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

To the extent I understand your post, it seems as if I'm stuck.

The somewhat odd thing is that the macro recorder seems to reach for
AutoText or BuildingBlocks, if that's similar. Is that where the page
numbers
used by the Insert Page Number tab live?

Anyway, I guess that's the end of the road on this one. Seems very strange
that something seemingly so simple crashes.

Thanks again,

Barnet

"John... Visio MVP" wrote:

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







Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie question - how can I run a macro on a protected document Mayavi New Users 2 April 11th 07 05:26 PM
[newbie] better vba coding [email protected] Microsoft Word Help 5 September 14th 05 06:23 PM
NewBie Question 2 Please Help Tom Grassi New Users 2 September 9th 05 05:03 PM
Newbie to Word Please help Tom Grassi New Users 8 September 9th 05 06:07 AM
Newbie can't get MM to work JLB Mailmerge 7 April 11th 05 07:26 AM


All times are GMT +1. The time now is 04:27 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"