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
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Does it work if you remove this line:

Code:
Application.PrintCommunication = False
 
Upvote 0
Actually it does :-D 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
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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