A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

word 2007 macro



 
 
Thread Tools Display Modes
  #1  
Old March 22nd, 2009, 10:44 PM posted to microsoft.public.word.newusers
perkin5
external usenet poster
 
Posts: 3
Default word 2007 macro

I am trying to record a macro to add the filepath to the page footer.
Having saved the page and recorded the macro, I get an error message:
Run-time error 5941. The requested member of the collection does not
exist.

The debugger shows the following code:

Sub Macro1()
'
' Macro1 Macro
'
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"FILENAME ", PreserveFormatting:=True
End Sub
Sub Macro2()
'
' Macro2 Macro
'
'
WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntri es("
Blank").Insert _
Whe=Selection.Range, RichText:=True
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"FILENAME ", PreserveFormatting:=True
End Sub

The two lines beginning 'ActiveDocument...' are highlighted.

Can anyone help me to sort this out?
  #2  
Old March 23rd, 2009, 02:17 AM posted to microsoft.public.word.newusers
Doug Robbins - Word MVP on news.microsoft.com
external usenet poster
 
Posts: 409
Default word 2007 macro

The following will add a { filename \p } field to the primary footer of the
first section of the document that is active when it is run:

With ActiveDocument
.Fields.Add .Sections(1).Footers(wdHeaderFooterPrimary).Range,
wdFieldEmpty, "filename \p"
End With

It would be better however to create a new template in which you have this
field already inserted and then use that template to create the documents
that you want to have this information in the footer. (Do not add the field
to the Normal.Dot Template).

--
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, originally posted via msnews.microsoft.com

"perkin5" wrote in message
...
I am trying to record a macro to add the filepath to the page footer.
Having saved the page and recorded the macro, I get an error message:
Run-time error 5941. The requested member of the collection does not
exist.

The debugger shows the following code:

Sub Macro1()
'
' Macro1 Macro
'
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"FILENAME ", PreserveFormatting:=True
End Sub
Sub Macro2()
'
' Macro2 Macro
'
'
WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntri es("
Blank").Insert _
Whe=Selection.Range, RichText:=True
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"FILENAME ", PreserveFormatting:=True
End Sub

The two lines beginning 'ActiveDocument...' are highlighted.

Can anyone help me to sort this out?



  #3  
Old March 23rd, 2009, 10:04 AM posted to microsoft.public.word.newusers
perkin5
external usenet poster
 
Posts: 3
Default word 2007 macro

On Mar 23, 2:17*am, "Doug Robbins - Word MVP on news.microsoft.com"
wrote:
The following will add a { filename \p } field to the primary footer of the
first section of the document that is active when it is run:

With ActiveDocument
* * .Fields.Add .Sections(1).Footers(wdHeaderFooterPrimary).Range,
wdFieldEmpty, "filename \p"
End With

It would be better however to create a new template in which you have this
field already inserted and then use that template to create the documents
that you want to have this information in the footer. *(Do not add the field
to the Normal.Dot Template).

--
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, originally posted via msnews.microsoft.com

"perkin5" wrote in message

...

I am trying to record a macro to add the filepath to the page footer.
Having saved the page and recorded the macro, I get an error message:
Run-time error 5941. The requested member of the collection does not
exist.


The debugger shows the following code:


Sub Macro1()
'
' Macro1 Macro
'
'
* *Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
* * * *"FILENAME *", PreserveFormatting:=True
End Sub
Sub Macro2()
'
' Macro2 Macro
'
'
* *WordBasic.ViewFooterOnly
* *ActiveDocument.AttachedTemplate.BuildingBlockEntr ies("
Blank").Insert _
* * * *Whe=Selection.Range, RichText:=True
* *Selection.Delete Unit:=wdCharacter, Count:=1
* *Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
* * * *"FILENAME *", PreserveFormatting:=True
End Sub


The two lines beginning 'ActiveDocument...' are highlighted.


Can anyone help me to sort this out?


Hi Doug,

Many thanks for this good advice. Code noted but I will use the
template route. Still a bit annoying that Word 2007 doesn't always do
what it says on the tin.

Mike
  #4  
Old March 23rd, 2009, 05:27 PM posted to microsoft.public.word.newusers
pepper
external usenet poster
 
Posts: 77
Default word 2007 macro

1. Move your cursor to where the filename should appear.
2. In the Insert tab, Text group, click the Quick Parts button, then choose
Field.
3. In the Field box, change the Categories: to Document Information.
4. In the Field Names: list, choose FileName.
5. If you want the path included, under Field Option, check the Include the
Path box.
6. In the Field Properties section, you can specify the format, ie.
uppercase, lowercase, for how the path/filename displays.

I put a button on the QAT to add a field.




"perkin5" wrote:

On Mar 23, 2:17 am, "Doug Robbins - Word MVP on news.microsoft.com"
wrote:
The following will add a { filename \p } field to the primary footer of the
first section of the document that is active when it is run:

With ActiveDocument
.Fields.Add .Sections(1).Footers(wdHeaderFooterPrimary).Range,
wdFieldEmpty, "filename \p"
End With

It would be better however to create a new template in which you have this
field already inserted and then use that template to create the documents
that you want to have this information in the footer. (Do not add the field
to the Normal.Dot Template).

--
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, originally posted via msnews.microsoft.com

"perkin5" wrote in message

...

I am trying to record a macro to add the filepath to the page footer.
Having saved the page and recorded the macro, I get an error message:
Run-time error 5941. The requested member of the collection does not
exist.


The debugger shows the following code:


Sub Macro1()
'
' Macro1 Macro
'
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"FILENAME ", PreserveFormatting:=True
End Sub
Sub Macro2()
'
' Macro2 Macro
'
'
WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntri es("
Blank").Insert _
Whe=Selection.Range, RichText:=True
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"FILENAME ", PreserveFormatting:=True
End Sub


The two lines beginning 'ActiveDocument...' are highlighted.


Can anyone help me to sort this out?


Hi Doug,

Many thanks for this good advice. Code noted but I will use the
template route. Still a bit annoying that Word 2007 doesn't always do
what it says on the tin.

Mike

  #5  
Old March 24th, 2009, 12:50 PM posted to microsoft.public.word.newusers
perkin5
external usenet poster
 
Posts: 3
Default word 2007 macro

On Mar 23, 5:27*pm, Pepper wrote:
1. * * *Move your cursor to where the filename should appear.
2. * * *In the Insert tab, Text group, click the Quick Parts button, then choose
Field.
3. * * *In the Field box, change the Categories: to Document Information.
4. * * *In the Field Names: list, choose FileName.
5. * * *If you want the path included, under Field Option, check the Include the
Path box.
6. * * *In the Field Properties section, you can specify the format, ie.
uppercase, *lowercase, for how the path/filename displays.

I put a button on the QAT to add a field.

"perkin5" wrote:
On Mar 23, 2:17 am, "Doug Robbins - Word MVP on news.microsoft.com"
wrote:
The following will add a { filename \p } field to the primary footer of the
first section of the document that is active when it is run:


With ActiveDocument
* * .Fields.Add .Sections(1).Footers(wdHeaderFooterPrimary).Range,
wdFieldEmpty, "filename \p"
End With


It would be better however to create a new template in which you have this
field already inserted and then use that template to create the documents
that you want to have this information in the footer. *(Do not add the field
to the Normal.Dot Template).


--
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, originally posted via msnews.microsoft.com


"perkin5" wrote in message


....


I am trying to record a macro to add the filepath to the page footer..
Having saved the page and recorded the macro, I get an error message:
Run-time error 5941. The requested member of the collection does not
exist.


The debugger shows the following code:


Sub Macro1()
'
' Macro1 Macro
'
'
* *Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
* * * *"FILENAME *", PreserveFormatting:=True
End Sub
Sub Macro2()
'
' Macro2 Macro
'
'
* *WordBasic.ViewFooterOnly
* *ActiveDocument.AttachedTemplate.BuildingBlockEntr ies("
Blank").Insert _
* * * *Whe=Selection.Range, RichText:=True
* *Selection.Delete Unit:=wdCharacter, Count:=1
* *Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
* * * *"FILENAME *", PreserveFormatting:=True
End Sub


The two lines beginning 'ActiveDocument...' are highlighted.


Can anyone help me to sort this out?


Hi Doug,


Many thanks for this good advice. Code noted but I will use the
template route. Still a bit annoying that Word 2007 doesn't always do
what it says on the tin.


Mike


Many thanks but I had actually got that far. My problem was in turning
it into a macro. Doug Robbins recommended using a template instead
which seems like good advice.

Mike
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:01 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.