Adding horizontal line to footer (VBA)

deckerp

Active Member
Joined
Feb 12, 2010
Messages
319
Office Version
  1. 365
Hi,

I would like to add a horizontal line above my footer. Does someone know how to do this?
Thanks.

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
'Calculate

Dim booIsSaved As Boolean
Dim strDatInfo As String

With ThisWorkbook
booIsSaved = .Saved
If .Path <> "" Then
strDatInfo = _
.BuiltinDocumentProperties("Last save time")
Else
strDatInfo = "not saved"
End If

If Year(Now()) = 2011 Then
    ActiveSheet.PageSetup.LeftFooter = "&08" & "Copyright © " & Year(Now) & " | Last saved: " & strDatInfo & Chr(10) & "&Z&F"
Else
    ActiveSheet.PageSetup.LeftFooter = "&08" & "Copyright © 2011-" & Year(Now) & " | Last saved: " & strDatInfo & Chr(10) & "&Z&F"
End If

.Saved = booIsSaved
ActiveSheet.PageSetup.RightFooter = _
    "&08" & "Page " & "&P" & " of " & "&N" & Chr(10)

End With
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
See if adding something like this to your footers help.
Rich (BB code):
ActiveSheet.PageSetup.LeftFooter = String(100, "_") & vbLf & "&08" & "Copyright © " & Year(Now) & " | Last saved: " & strDatInfo & Chr(10) & "&Z&F"
 
Upvote 0
many thanks, it works partly.

how can I include the line to the right section too (no gap between the lines) or simply put it across the whole page (100%) ?

Code:
If Year(Now()) = 2011 Then
    ActiveSheet.PageSetup.LeftFooter = String(100, "_") & vbLf & "&08" & "Copyright © " & Year(Now) & " | Last saved: " & strDatInfo & Chr(10) & "&Z&F"
Else
    ActiveSheet.PageSetup.LeftFooter = String(100, "_") & vbLf & "&08" & "Copyright © 2011-" & Year(Now) & " | Last saved: " & strDatInfo & Chr(10) & "&Z&F"
End If

.Saved = booIsSaved
    [B]ActiveSheet.PageSetup.RightFooter = _[/B]
"&08" & "Page " & "&P" & " of " & "&N" & Chr(10)
End With
End Sub
 
Upvote 0
Try experimenting by changing the 100 to other numbers. 109 was about right for my page. I think you just need it in the left footer if you want it to go right across the page.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,261
Members
452,901
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top