Linking document name and a heading in the document

J

Jenny

I would like to link the name of a word document with a heading in the
document. For example I have a document called '1.1 Kitchen Equipment' and
in the document the heading is also '1.1 Kitchen Equipment'. When I change
the document's name to say '1.2 Kitchen Equipment' I want the heading in the
document to chang also.

Can someone give me a hand with writting VBA for that. I assume this would
be too difficult to do with just a macro.

Please help me out.
 
D

Doug Robbins - Word MVP

Use a StyleRef field.

--
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
 
J

Jenny

Hello Doug,

I had a look in help but it's not very clear about how to use StyleRef. I
couldn't make it work.

Could you please explain how to use StyleRef for my problem in particular?
 
G

Gordon Bentley-Mix

Jenny,

I don't think a StyleRef field is quite what you're looking for. What you
need is something similar to what you're doing in your other thread with the
filename in the footer. However, if you just use a filename field, you'll get
the whole filename - including the '.doc'. I don't imagine this is what you
want.

There may be a way around this using a custom document property or document
variable and a bit of code that parses the filename and writes just the part
you want (without the '.doc') into the document property or variable. Then
you could use a DOCPROPERTY or DOCVARIABLE field to display the shortened
filename.

However, to do it properly is not as easy as it sounds. Because there's no
'OnSave' event, you would have to write code around the DocumentBeforeSave
event. (See the VBA help - not very 'novice friendly'.) And then, if this was
my project, I'd want to do some comparisons to see if the filename had
changed before I ran the code. I'd probably also want to check the filename
on open as well, just in case it got renamed through Windows Exploder. And
finally, there's the whole matter of updating the field in the document -
again something you would maybe want to do when you either opened or closed
the document or both. (And of course there's error handling and code
efficiency issues and everything else that comes with this sort of project.)
In the end I think you might be better off just updating the heading manually
- at least, that's what I would do unless I had a _really_ good reason to
automate it.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
J

Jenny

Thank you Gordon. I will probably do it manually because it is just too time
consuming with the code.
 

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