Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim fname As String, str As String, i As Long, myLen As Long, _
cnt As Long, sname As String, myset As String
fname = ActiveWorkbook.FullName
sname = ActiveWorkbook.Name
myLen = Len(fname)
cnt = 0
On Error GoTo lessThanAmt
For i = myLen To 1 Step -1
If cnt > 2 Then
str = Right(fname, myLen - i + 1)
Exit For
End If
If Mid(fname, i - 1, 1) = "\" Then
cnt = cnt + 1
End If
Next i
If str <> "" Then
str = ".." & Left(str, Len(str) - Len(ActiveWorkbook.Name)) & sname
End If
With ActiveSheet.PageSetup
myset = "&""Tahoma,Italic""&10"
.RightFooter = myset & str
End With
Exit Sub
lessThanAmt:
With ActiveSheet.PageSetup
myset = "&""Tahoma,Italic""&10"
.RightFooter = myset & fname
End With
Err.Clear
End Sub
|