У меня много-много различных файлов,которые находятся в разных папках.
Могу ли я, когда печатаю файл, сделать вывод пути к нему в колонтитул файла?
Option Explicit
'Enum не поддерживается в VBA 97!
Public Const xlApplyToLeftFooter As Integer = 0
Public Const xlApplyToCenterFooter As Integer = 1
Public Const xlApplyToRightFooter As Integer = 2
Public Sub ApplyFooterFilePath(WhichFooter As Integer, Optional ToSingleSheet As Excel.Worksheet = Nothing)
Dim a As Worksheet
If ToSingleSheet Is Nothing Then
For Each a In Worksheets
Select Case WhichFooter
Case xlApplyToLeftFooter
a.PageSetup.LeftFooter = ActiveWorkbook.FullName
Case xlApplyToCenterFooter
a.PageSetup.CenterFooter = ActiveWorkbook.FullName
Case xlApplyToRightFooter
a.PageSetup.RightFooter = ActiveWorkbook.FullName
End Select
Next
Else
With ToSingleSheet.PageSetup
Select Case WhichFooter
Case xlApplyToLeftFooter
.LeftFooter = ActiveWorkbook.FullName
Case xlApplyToCenterFooter
.CenterFooter = ActiveWorkbook.FullName
Case xlApplyToRightFooter
.RightFooter = ActiveWorkbook.FullName
End Select
End With
End If
End Sub
Sub TestSub()
ApplyFooterFilePath xlApplyToCenterFooter, Worksheets(1)
End Sub
Public Sub RemoveFooterFilePath(WhichFooter As Integer, Optional ToSingleSheet As Excel.Worksheet = Nothing)
If ToSingleSheet Is Nothing Then
For Each a In Worksheets
Select Case WhichFooter
Case xlApplyToLeftFooter
a.PageSetup.LeftFooter = Application.Replace(a.PageSetup.LeftFooter, ActiveWorkbook.FullName, "")
Case xlApplyToCenterFooter
a.PageSetup.CenterFooter = Application.Replace(a.PageSetup.CenterFooter, ActiveWorkbook.FullName, "")
Case xlApplyToRightFooter
a.PageSetup.RightFooter = Application.Replace(a.PageSetup.RightFooter, ActiveWorkbook.FullName, "")
End Select
Next
Else
With ToSingleSheet.PageSetup
Select Case WhichFooter
Case xlApplyToLeftFooter
.LeftFooter = Application.Replace(.LeftFooter, ActiveWorkbook.FullName, "")
Case xlApplyToCenterFooter
.CenterFooter = Application.Replace(.CenterFooter, ActiveWorkbook.FullName, "")
Case xlApplyToRightFooter
.RightFooter = Application.Replace(.RightFooter, ActiveWorkbook.FullName, "")
End Select
End With
End If
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 88