Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

header filename w/o extension

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Laura G - 23 Nov 2005 17:40 GMT
how do you insert the filename without the extension into the header.
Karl E. Peterson - 23 Nov 2005 17:48 GMT
> 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?
--
Working without a .NET?
http://classicvb.org/
Laura G - 23 Nov 2005 18:09 GMT
stripping the extension

> > how do you insert the filename without the extension into the header.
>
[quoted text clipped - 3 lines]
> Working without a .NET?
> http://classicvb.org/
Karl E. Peterson - 23 Nov 2005 19:51 GMT
>>> how do you insert the filename without the extension into the
>>> header.
[quoted text clipped - 3 lines]
>
> stripping the extension

BaseFileName = Left$(FileName, InStrRev(FileName, ".") - 1)
--
Working without a .NET?
http://classicvb.org/
Jonathan West - 23 Nov 2005 17:54 GMT
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.

Signature

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

> how do you insert the filename without the extension into the header.
Laura G - 23 Nov 2005 18:26 GMT
that's exactly what i need...but i'm not familar with that function.  point
me in the right direction?

> Hi Laura,
>
[quoted text clipped - 8 lines]
>
> > how do you insert the filename without the extension into the header.
Laura G - 23 Nov 2005 18:30 GMT
Actually, I would like to use everything to the LEFT of a specific word.  
Will not always be in same location though...

> Hi Laura,
>
[quoted text clipped - 8 lines]
>
> > how do you insert the filename without the extension into the header.
Jonathan West - 23 Nov 2005 19:42 GMT
Try this

strName = ActiveDocument.Name
strName = Left$(strName, InstrRev(strName, ".") - 1)

Signature

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

> Actually, I would like to use everything to the LEFT of a specific word.
> Will not always be in same location though...
[quoted text clipped - 13 lines]
>>
>> > how do you insert the filename without the extension into the header.
Karl E. Peterson - 23 Nov 2005 19:49 GMT
> 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

--
Working without a .NET?
http://classicvb.org/
Jonathan West - 23 Nov 2005 19:56 GMT
Hi Karl,

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

Signature

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

>> Actually, I would like to use everything to the LEFT of a specific
>> word. Will not always be in same location though...
[quoted text clipped - 10 lines]
> Working without a .NET?
> http://classicvb.org/
Karl E. Peterson - 23 Nov 2005 20:34 GMT
> 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
--
Working without a .NET?
http://classicvb.org/

>>> Actually, I would like to use everything to the LEFT of a specific
>>> word. Will not always be in same location though...
[quoted text clipped - 10 lines]
>> Working without a .NET?
>> http://classicvb.org/
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.