Macro to insert / update footer 
Author Message
 Macro to insert / update footer

Hello,

At work we've implemented a new file structure. To help our users file and
retrieve their document we would like to create a macro in their normal.dot
under 'AutoClose' (activates when they close a document) so it inserts the
filename and path (using AutoText) into the footer.

I started this by simply recording a macro: View - Header & Footer, switch
to footer, Insert - AutoText - Path & Filename.
This works fine, except when they re-open the document to edit something,
upon closing the document, another Path & Filename is inserted.
A cheap way around this is to Edit - Select All once into the footer, so
inserting the path again will overwrite the original one. But the problem
with this is, if the user wants to Page Numbering or anything else in their
footer also, this will also be overwritten.

I'd like a macro that says, if there isn't a Path & Filename in the footer,
then insert one. If there is, then just update it (not insert another one).
I've tried some VBA, using an IF statement to detect whether the Path &
Filename is already there, but my skills in VBA are rather basic.

Any help on this would be greatly appreciated by a stuck IT Unit and a
building of users!

Regards,

Mark

Suffolk, England.



Thu, 08 Jul 2004 01:36:48 GMT  
 Macro to insert / update footer
Hi Mark,

If I were developing the routine, I'd be worried that the "Path & Filename
in the footer" would not be the correct one. Therefore, I'd accomplish the
task you've outlined by manually adding a custom document property (let's
call it "sPath") to Normal.dot.

On the File menu, click Properties. On the Custom tab, in the Name box, type
"sPath" (w/o the quotation marks). Leave its type set to Text. In the Value
box, type "C:\". It'll change, so it doesn't matter. Click Add. In
Normal.dot, add a filed that looks like { DOCPROPERTY "sPath"  \*
MERGEFORMAT } to the footer.

'---------------------------
Public Sub UpdatesPath()
With ActiveDocument
    .CustomDocumentProperties("sPath") = ActiveDocument.FullName
    .StoryRanges(wdPrimaryFooterStory).Fields.Update
End With
End Sub
'---------------------------

Now, intercept each of the save routines (FileSave, FileSaveAs,
FileSaveAll). At the end of each, call the UpdatesPath routine. You can also
call the UpdatesPath routine from AutoClose.

HTH


Quote:
> Hello,

> At work we've implemented a new file structure. To help our users file and
> retrieve their document we would like to create a macro in their
normal.dot
> under 'AutoClose' (activates when they close a document) so it inserts the
> filename and path (using AutoText) into the footer.

> I started this by simply recording a macro: View - Header & Footer, switch
> to footer, Insert - AutoText - Path & Filename.
> This works fine, except when they re-open the document to edit something,
> upon closing the document, another Path & Filename is inserted.
> A cheap way around this is to Edit - Select All once into the footer, so
> inserting the path again will overwrite the original one. But the problem
> with this is, if the user wants to Page Numbering or anything else in
their
> footer also, this will also be overwritten.

> I'd like a macro that says, if there isn't a Path & Filename in the
footer,
> then insert one. If there is, then just update it (not insert another
one).
> I've tried some VBA, using an IF statement to detect whether the Path &
> Filename is already there, but my skills in VBA are rather basic.

> Any help on this would be greatly appreciated by a stuck IT Unit and a
> building of users!

> Regards,

> Mark

> Suffolk, England.



Fri, 09 Jul 2004 21:49:54 GMT  
 Macro to insert / update footer
Hi Dave. Interesting. Thanks for this. I'll have to follow your instructions
and test it out. Think I understand what it's doing.

Mark.


Quote:
> Hi Mark,

> If I were developing the routine, I'd be worried that the "Path & Filename
> in the footer" would not be the correct one. Therefore, I'd accomplish the
> task you've outlined by manually adding a custom document property (let's
> call it "sPath") to Normal.dot.

> On the File menu, click Properties. On the Custom tab, in the Name box,
type
> "sPath" (w/o the quotation marks). Leave its type set to Text. In the
Value
> box, type "C:\". It'll change, so it doesn't matter. Click Add. In
> Normal.dot, add a filed that looks like { DOCPROPERTY "sPath"  \*
> MERGEFORMAT } to the footer.

> '---------------------------
> Public Sub UpdatesPath()
> With ActiveDocument
>     .CustomDocumentProperties("sPath") = ActiveDocument.FullName
>     .StoryRanges(wdPrimaryFooterStory).Fields.Update
> End With
> End Sub
> '---------------------------

> Now, intercept each of the save routines (FileSave, FileSaveAs,
> FileSaveAll). At the end of each, call the UpdatesPath routine. You can
also
> call the UpdatesPath routine from AutoClose.

> HTH



> > Hello,

> > At work we've implemented a new file structure. To help our users file
and
> > retrieve their document we would like to create a macro in their
> normal.dot
> > under 'AutoClose' (activates when they close a document) so it inserts
the
> > filename and path (using AutoText) into the footer.

> > I started this by simply recording a macro: View - Header & Footer,
switch
> > to footer, Insert - AutoText - Path & Filename.
> > This works fine, except when they re-open the document to edit
something,
> > upon closing the document, another Path & Filename is inserted.
> > A cheap way around this is to Edit - Select All once into the footer, so
> > inserting the path again will overwrite the original one. But the
problem
> > with this is, if the user wants to Page Numbering or anything else in
> their
> > footer also, this will also be overwritten.

> > I'd like a macro that says, if there isn't a Path & Filename in the
> footer,
> > then insert one. If there is, then just update it (not insert another
> one).
> > I've tried some VBA, using an IF statement to detect whether the Path &
> > Filename is already there, but my skills in VBA are rather basic.

> > Any help on this would be greatly appreciated by a stuck IT Unit and a
> > building of users!

> > Regards,

> > Mark

> > Suffolk, England.



Sat, 10 Jul 2004 03:45:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Macro to insert / update footer

2. EZ - Need macro to insert path into footer

3. Insert AutoText in Footer via Macro

4. Updating fields: footer doesn't update right

5. Align only last-inserted paragraph in footer

6. Inserting footer

7. Insert text and date in Footer/Header with VBA

8. Problem inserting footers

9. How to insert txt in a footer w/o deleting existing text

10. Inserting page numbers in footer with word automation

11. oledb: foxpro index file not updating after inserts and updates

12. Inserting headers and footers in richtextbox control

 

 
Powered by phpBB® Forum Software