header filename w/o extension

K

Karl E. Peterson

Laura said:
how do you insert the filename without the extension into the header.

What are you having trouble with -- stripping the extension off the
filename, or adding text to the header?
 
J

Jonathan West

Hi Laura,

If you are wanting to use the FILENAME field to do this, then no, you can't
omit the filename extension.

if you want to use VBA to insert the text of the filename as text, then
ActiveDocument.Name returns the filename, and you can use the instrRev
function to find the position of the last period in the name, and then use
the Left$ function to trim the string to the appropriate length before
inserting it.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
L

Laura G

stripping the extension

Karl E. Peterson said:
What are you having trouble with -- stripping the extension off the
filename, or adding text to the header?
 
L

Laura G

that's exactly what i need...but i'm not familar with that function. point
me in the right direction?
 
L

Laura G

Actually, I would like to use everything to the LEFT of a specific word.
Will not always be in same location though...
 
K

Karl E. Peterson

Laura said:
Actually, I would like to use everything to the LEFT of a specific
word. Will not always be in same location though...

In that case, assuming SomeText is the variable that holds the original
string...

nPos = Instr(SomeText, SpecificWord)
If nPos Then
WhatYouWant = Left$(SomeText, nPos - 1)
End If
 
K

Karl E. Peterson

Jonathan said:
Hi Karl,

To get the last occurrence (instead of the first) of SpecificWord,
you need to use InstrRev, not Instr...

Whoops, of course. Typed too fast. (At least I got it right in one post.)

Thanks... Karl
 

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