Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Copy contents of Excel Right Header to a cell

The code below is provided to show what I need to do, but I find that I cannot successfully copy the contents of the Right Header to the clipboard with VBA no matter the method or how short or elaborate the code. Maybe it just can’t be done? I am trying to avoid using pop up boxes to capture data that users are already used to putting in the header.

Sub copyrightheader()

    ActiveSheet.PageSetup.RightHeader.Copy
    ActiveSheet.Range("J1").Select
    ActiveSheet.Paste
End Sub

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you look here: https://learn.microsoft.com/en-us/office/vba/api/excel.pagesetup.rightheader

…you can see that PageSetup.RightHeader reurns a String value, so you can assign that directly to a cell:

with ActiveSheet
    .Range("J1").Value = .PageSetup.RightHeader
end with
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading