Displaying only part of a filename

G

Guest

I'm trying to find a way to use the Filename field to display only part of
the filename. It needs to be dynamic so if the document name changes, the
field w/automatically update. I'm thinking something to the effect of
inserting a field then {Mid$({FileName},7,6)}. When I toggle the code the
whole thing disappears.
 
J

Jay Freedman

I'm trying to find a way to use the Filename field to display only part of
the filename. It needs to be dynamic so if the document name changes, the
field w/automatically update. I'm thinking something to the effect of
inserting a field then {Mid$({FileName},7,6)}. When I toggle the code the
whole thing disappears.

Sorry, there's no way to do this without actually writing a macro and
setting up some way to run it. The field isn't capable of that kind of
manipulation.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
G

Graham Mayor

As Jay says, you can't do this with a field. The macro equivalent would be

Sub InsertFnameOnly()
Dim pPathname As String
With ActiveDocument
If Not .Saved Then
.Save
End If
pPathname = Mid$(.Name, 7, 6)
End With
Selection.TypeText pPathname
End Sub

However this must be peculiar to the one document. Are you simply tryting to
remove the filename extension? If so

Sub InsertFnameOnly()
Dim pPathname As String
With ActiveDocument
If Not .Saved Then
.Save
End If
pPathname = Left$(.Name, (Len(.Name) - 4))
End With
Selection.TypeText pPathname
End Sub

would be nearer the mark.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Guest

Graham~

Thanks. We lots of ways of linking it to the save function, however we need
to avoid that.

We have a document management system that includes
libraryname - docnumb.version - documentreallylongnamebecauseouruserslikethem

All I want to snag is the docnumb.version, the application has way of
placing this in statically, or a simple text, however we need it to be
dynamic so when on the occassions when they do include the document number
and create a new version or new document that number changes. AND they don't
always want the number which is why we can't link it with the save as feature.

~Lori
 
J

Jay Freedman

Hi Lori,

I'm not sure what you're saying with "the application has way of placing
this in statically, or a simple text". Do you mean that the doc management
application can insert text in the body of the document, as opposed to (or
in addition to) setting the document's file name? Can it put that text in a
specific location in the document, such as inserting it as a new first
paragraph?

If so, write a macro to grab the necessary data from that text and place it
in a custom document property, and insert a DocProperty field in the footer
or wherever you want it. In cases where the user doesn't want the number to
appear, they can delete the DocProperty field while still leaving the custom
property in place (it would still be visible in the File > Properties >
Custom dialog).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
G

Guest

Jay~

Thank you. Yes different ways is what I'm looking for. I'm slowing
learning VB the hard way.

I will check into this, it's a good idea my only concern is the users would
have to keep updating the custom property, which is the same as running an
existing macro that puts the Document Number into the footer. I'm trying to
find a way that once the feild is inserted, the user doesn't have to do
anything again, it will automatically update.

The other issue is this application replaces the Word File>Properties w/it's
own Properties (ie Profile) screen.

I was hoping there was simple way to manipulate the {FILENAME} feild by
nesting it inside another field, such as {Mid$({FILENAME},7,6)}. But that
just disappears when I try it.

~Lori
 
J

Jay Freedman

If you write a macro and name it FileSaveAs, it will automatically
intercept the built-in Save As command (see
http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm). The
macro should:

- Display the Save As dialog to let the user (or the management app)
specify the new file name. In VBA, the .Display method of the dialog
object displays the dialog box but doesn't actually save the document,
so the macro just gets the path and name in a variable.

- Change the value of the custom document property if necessary.

- Update the DocProperty field in the footer.

- Use the .Save method to do the actual save with the new name.

A full discussion of this, if you need more direction, should be moved
into the microsoft.public.word.vba.beginners newsgroup.

You can forget about running VBA code inside a field -- it just
doesn't work. The closest you can get is a MacroButton field, which
runs a macro when you double-click it. It still isn't automatic.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
G

Guest

Jay~

I can not link it to the Save or Save As feature since that would effect all
docs created or modified, I only need it for certain docs.

~Lori
 
J

Jay Freedman

Is there any way the macro could automatically identify *which* documents it
should process? Is there some identifying characteristic of those documents?

The easiest case is when all the documents that need processing are based on
one template (or a small set of templates), and all the documents that don't
need processing are based on other templates. Then you can put the
FileSaveAs macro only the the specific template(s), and it will run only in
documents based on that template.

If that doesn't suit your situation, it's possible to build the macro to
look at whatever identifies the "right" documents and ignore all the "wrong"
documents -- but I can't tell you what that code might be until you can
state, simply and succinctly, what distinguishes "right" from "wrong". If
it's up to the user to decide, then the macro would have to display a Yes/No
message box.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
G

Guest

Jay~

User whim.

About 1/2 the docs will contain the document number, the rest won't. At
some point, and not always on the first version, someone will think it's
Jim-Dandy-Nice to have the doc.ver number so they can easily find it again if
they are reviewing a printed copy. Once the doc.ver number is inserted, it's
updated through it's various versions, subversion (and for some reason
complete document number change) until the document is ready to be published
(ie sent to client/customer or third party) when they will remove the
docnumber. Since some of these docs can have up to 10-15 versions (not
including multiple sub-version and whole-sale docnumber changes) they are
getting cranking about manually updating the number.

I've been on several lists, dealing w/our docmgmt sw company, and random
websurfing and am coming to the conclusion it can't be done and must now move
on to my next project of figuring out how to count dates in four different
Access tables and get them to display nicely on the main form.

Thanks for trying though.
~Lori
 

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