+ Reply to Thread
Results 1 to 5 of 5

How to format header footer when using BeforePrint to use a cell reference?

Hybrid View

  1. #1
    Registered User
    Join Date
    04-25-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    13

    How to format header footer when using BeforePrint to use a cell reference?

    Hi everyone,

    I have found great answers that come close to answering the question I have, but because I know nothing about VB, I don't know how to adapt those answers to get the exact solution I need. Here it is:

    Using Excel 2007, I am using a piece of code I found online to use a cell reference to populate the left header of my worksheet. The code is below. It works great. However I need the resulting text to be formatted in a particular way. The formatting I need is:

    Arial
    size 12
    bold
    RGB colors: 0,51,102

    So, how does the code below need to look to incorporate these specifications? If someone could rewrite it for me, I will be hugely grateful.

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    ActiveSheet.PageSetup.LeftHeader = ActiveSheet.Cells(4, 1)
    End Sub

    Thanks in advance,
    Frank

  2. #2
    Forum Contributor
    Join Date
    06-07-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: How to format header footer when using BeforePrint to use a cell reference?

    Try this (not sure about the color, try the macro recorder for that)

    ActiveSheet.PageSetup.LeftHeader = "&""Arial,Bold""&12" & ActiveSheet.Cells(4, 1)

  3. #3
    Registered User
    Join Date
    04-25-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to format header footer when using BeforePrint to use a cell reference?

    Yes! This does the trick. Thank you very much.

    Thanks for the suggestion on the text color. I would rather it be part of the BeforePrint function so that it happens automatically, rather than relying on someone having to run a macro each time.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: How to format header footer when using BeforePrint to use a cell reference?

    I reckon the suggestion was to see what the macro recorder produced when you do it manually, not to use a macro. you can use
        ActiveSheet.PageSetup.LeftHeader = "&""Arial,Bold""&12&K663300" & ActiveSheet.Cells(4, 1).value
    where 663300 is the hex value of your desired RGB.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    04-25-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: How to format header footer when using BeforePrint to use a cell reference?

    That did it! Fantastic! It gave me a brownish rather than bluish color, but I can figure out what the best hex value is. I just didn't know where or how to put it.

    You both rock. Thank you both for your time and expertise.

    This topic is solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1