Right end of full path in title bar

M

Mister.Fred.Ma

I followed http://wordtips.vitalnews.com/Pages/T0876_Full_Path_Names_in_Word.html
to get the full path of my documents in the title bar. The path is
quite long, so I only see the head of it, not the tail. That means I
often don't see the actual file name, nor the containing directory, or
parent directories. Even more problematic is that the corresponding
box in the taskbar shows only the first few characters of the path
i.e. "c:\AbC...".

Thanks!
 
J

Jay Freedman

I followed http://wordtips.vitalnews.com/Pages/T0876_Full_Path_Names_in_Word.html
to get the full path of my documents in the title bar. The path is
quite long, so I only see the head of it, not the tail. That means I
often don't see the actual file name, nor the containing directory, or
parent directories. Even more problematic is that the corresponding
box in the taskbar shows only the first few characters of the path
i.e. "c:\AbC...".

Thanks!

Here's a revision of the macro from that article that will show only
enough of the tail of the file path to fit the maximum number of
characters (which you can specify by setting the value of maxLen near
the top of the macro).

Public Sub WindowTitleWithPath()
' Changes window title to include path with filename
Dim NameArray As Variant
Dim NameStringL As String
Dim NameStringR As String
Dim Count As Long
Const maxLen = 100 ' set this value to fit your window width

' Check if any child windows open
' (avoid error if no active window)
If Windows.Count > 0 Then
NameStringL = ActiveDocument.FullName
If Len(NameStringL) > maxLen Then
' separate the folder names
NameArray = Split(NameStringL, "\")
' check the folder depth
Count = UBound(NameArray)
If Count > 3 Then
NameStringL = NameArray(0) & "\...\"
NameStringR = NameArray(Count)
Count = Count - 1

' continue adding folders to the left of the string
' until you run out of folders or one won't fit
Do While (Count > 0) And _
(Len(NameStringL) + Len(NameStringR) + _
Len(NameArray(Count)) < maxLen)
NameStringR = NameArray(Count) & "\" _
& NameStringR
Count = Count - 1
Loop

NameStringL = NameStringL & NameStringR
End If
End If

' Change the window's caption
ActiveWindow.Caption = NameStringL
End If
End Sub

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

Fred

Jay said:
Here's a revision of the macro from that article that will show only
enough of the tail of the file path to fit the maximum number of
characters (which you can specify by setting the value of maxLen near
the top of the macro).

Public Sub WindowTitleWithPath()
' Changes window title to include path with filename
Dim NameArray As Variant
Dim NameStringL As String
Dim NameStringR As String
Dim Count As Long
Const maxLen = 100 ' set this value to fit your window width

' Check if any child windows open
' (avoid error if no active window)
If Windows.Count > 0 Then
NameStringL = ActiveDocument.FullName
If Len(NameStringL) > maxLen Then
' separate the folder names
NameArray = Split(NameStringL, "\")
' check the folder depth
Count = UBound(NameArray)
If Count > 3 Then
NameStringL = NameArray(0) & "\...\"
NameStringR = NameArray(Count)
Count = Count - 1

' continue adding folders to the left of the string
' until you run out of folders or one won't fit
Do While (Count > 0) And _
(Len(NameStringL) + Len(NameStringR) + _
Len(NameArray(Count)) < maxLen)
NameStringR = NameArray(Count) & "\" _
& NameStringR
Count = Count - 1
Loop

NameStringL = NameStringL & NameStringR
End If
End If

' Change the window's caption
ActiveWindow.Caption = NameStringL
End If
End Sub

Thanks, Jay. I shall give it a try when I get back to the location where I'm
set up to use MS office.

F.

P.S. Strange that a subject or author search on grouples doesn't find this thread.
 
M

Mister.Fred.Ma

Here's a revision of the macro from that article that will show only
enough of the tail of the file path to fit the maximum number of
characters (which you can specify by setting the value of maxLen near
the top of the macro).

Public Sub WindowTitleWithPath()
' Changes window title to include path with filename
Dim NameArray As Variant
Dim NameStringL As String
Dim NameStringR As String
Dim Count As Long
Const maxLen = 100 ' set this value to fit your window width

' Check if any child windows open
' (avoid error if no active window)
If Windows.Count > 0 Then
NameStringL = ActiveDocument.FullName
If Len(NameStringL) > maxLen Then
' separate the folder names
NameArray = Split(NameStringL, "\")
' check the folder depth
Count = UBound(NameArray)
If Count > 3 Then
NameStringL = NameArray(0) & "\...\"
NameStringR = NameArray(Count)
Count = Count - 1

' continue adding folders to the left of the string
' until you run out of folders or one won't fit
Do While (Count > 0) And _
(Len(NameStringL) + Len(NameStringR) + _
Len(NameArray(Count)) < maxLen)
NameStringR = NameArray(Count) & "\" _
& NameStringR
Count = Count - 1
Loop

NameStringL = NameStringL & NameStringR
End If
End If

' Change the window's caption
ActiveWindow.Caption = NameStringL
End If
End Sub


Hi, Jay,

Your macro works well as advertised.

I don't suppose there is a simple way to dynamically and automatically
adjust the portion of the path shown according to the current size of
the window? I know I'm asking for the stars, but as well, the ideal
solution wouldn't depend on an character count (even a dynamically
adjust one) so that variable width font can be used.

I'm not implying that this is easy to do. In fact, I'm guessing not,
since it probably would nave been done by now if it was. But worth
publically asking about.
 
J

Jay Freedman

Hi, Jay,

Your macro works well as advertised.

I don't suppose there is a simple way to dynamically and automatically
adjust the portion of the path shown according to the current size of
the window? I know I'm asking for the stars, but as well, the ideal
solution wouldn't depend on an character count (even a dynamically
adjust one) so that variable width font can be used.

I'm not implying that this is easy to do. In fact, I'm guessing not,
since it probably would nave been done by now if it was. But worth
publically asking about.

This is just as much a guesswork solution as the 100-character fixed limit,
but it may suffice. Remove the line

Const maxLen = 100 ' set this value to fit your window width

and replace it with these two lines:

Dim maxLen As Long
maxLen = 13 * (PointsToInches(ActiveWindow.Width) - 1)

The number 13 is roughly based on the average number of characters per inch
for the default window title font in the standard Windows XP scheme (10 pt
Trebuchet, which is a proportional font). Of course, that font can be
modified in the Display > Appearance > Advanced dialog of Windows, and
you'll need to adjust the number if you have a different title font. The "-
1" allows for the space, roughly 1 inch, used by the icon and buttons on the
title bar.

There's no way to get completely away from a character count unless you want
to get deep into Windows API programming. The problem is that native VBA has
no way to say "tell me the width in points of this specific string, in this
font at this size". To do that, you have to go through a fairly complex
series of API function calls. For that matter, native VBA has no way to ask
what the title bar's font and size are; that would also require API calls.

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

Mister.Fred.Ma

This is just as much a guesswork solution as the 100-character fixed limit,
but it may suffice. Remove the line

Const maxLen = 100 ' set this value to fit your window width

and replace it with these two lines:

Dim maxLen As Long
maxLen = 13 * (PointsToInches(ActiveWindow.Width) - 1)

The number 13 is roughly based on the average number of characters per inch
for the default window title font in the standard Windows XP scheme (10 pt
Trebuchet, which is a proportional font). Of course, that font can be
modified in the Display > Appearance > Advanced dialog of Windows, and
you'll need to adjust the number if you have a different title font. The "-
1" allows for the space, roughly 1 inch, used by the icon and buttons on the
title bar.

There's no way to get completely away from a character count unless you want
to get deep into Windows API programming. The problem is that native VBA has
no way to say "tell me the width in points of this specific string, in this
font at this size". To do that, you have to go through a fairly complex
series of API function calls. For that matter, native VBA has no way to ask
what the title bar's font and size are; that would also require API calls.

Thanks, Jay. I'll give it a go at my next opportunity in front of the
machine of interest.

Fred
 

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