Macro for Header/Footer run in debug, not in runtime

Llupo01

Active Member
Joined
Aug 17, 2015
Messages
296
Hello,

can anybody help pls? I have file with userform updating header and footer data to another sheet. When exporting data sheet to pdf, there is one part of code, which updates Header and footer according data saved on 'settings sheet'. It works in debug mode, but not working in runtime. It just do not update leftfooter...

below is part of the code where creating simple string variables for header/footer and then applying data on sheet 'sh'.

Thank you in advance.

Brgds,
Tomas


VBA Code:
strCentHeaderText = "&""-,Bold""&18&K63BA26" & UCase(office) & " data list" & ""
strRightHeader = "&""-,Bold""&8&K00-049Version: " & strVer & Chr(10) & "First date: " & strFirstDate & Chr(10) & "Second date: " & strSecondDate
strLeftFooter = "&""-,Bold""&8&K00-045Owner: " & strOwner
strCenterFooter = "&""-,Bold""&K00-047XX1 |  XX2   |  XX3  |   XX4 "

Application.PrintCommunication = False
    With sh.PageSetup
        .LeftHeader = "&G"
        .CenterHeader = strCentHeaderText
        .RightHeader = strRightHeader
        .LeftFooter = strLeftFooter
        .CenterFooter = strCenterFooter
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.1)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .Zoom = 96
        .PrintErrors = xlPrintErrorsDisplayed
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .ScaleWithDocHeaderFooter = True
        .AlignMarginsHeaderFooter = False
        .EvenPage.LeftHeader.text = ""
        .EvenPage.CenterHeader.text = ""
        .EvenPage.RightHeader.text = ""
        .EvenPage.LeftFooter.text = ""
        .EvenPage.CenterFooter.text = ""
        .EvenPage.RightFooter.text = ""
        .FirstPage.LeftHeader.text = ""
        .FirstPage.CenterHeader.text = ""
        .FirstPage.RightHeader.text = ""
        .FirstPage.LeftFooter.text = ""
        .FirstPage.CenterFooter.text = ""
        .FirstPage.RightFooter.text = ""
    End With
Application.PrintCommunication = True
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,834
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Does it work if you remove this line:

Code:
Application.PrintCommunication = False
 

Llupo01

Active Member
Joined
Aug 17, 2015
Messages
296
Actually it does :biggrin: I did try to remove it before, but it did not work, because I had one more line there in pagesetup and it was following one:
VBA Code:
.PageSetup.FitToPagesWide = True
Where I had to turn off printcommunication. Thank you :) all seems to be fine now
 

Watch MrExcel Video

Forum statistics

Threads
1,119,115
Messages
5,576,191
Members
412,705
Latest member
Collie
Top