+ Reply to Thread
Results 1 to 8 of 8

VBA Code to Pass String into Page Header

  1. #1
    Forum Contributor
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    Excel 365
    Posts
    129

    VBA Code to Pass String into Page Header

    I've got a template that I am trying to use for multiple reports. Depending on which macro gets run, I want it to put a string into the header so I know which report is generated. Here are the issues that I'm having:

    1. I use a picture in the center space of the header and eventhough I want my Report type text to be displayed in the middle of the page, I can't get the text to run ontop of the picture unless it is in the left header field.
    2. Since I have to use the left header field, I need to add spaces to the Header to Kick the Text into the center-ish place on the report, but VBA is not liking my " " designation.
    3. Finally, the code below works (minus the spacing being done correctly), however I can't get VBA to pass the variable into the header. Therefore, the code below just puts "HeaderName" into the header instead of "Annual Report"

    'start header
    Please Login or Register  to view this content.
    Any ideas?
    Last edited by jeffreybrown; 05-12-2020 at 02:32 PM. Reason: Please use code tags!

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Code to Pass String into Page Header

    Maybe: But not sure what you want

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    Excel 365
    Posts
    129

    Re: VBA Code to Pass String into Page Header

    Hi xlAdept,

    Thanks for your help again. Unfortunately, that code didn't work for me. Attached is a sample of what I would like to accomplish.

    I'll need to fine tune this, but I think if I use Arial Nova Font (size 11/Bold), hit enter 4 times, and use around 86 spaces, that puts me pretty close to where I am hoping to get the Header string.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,261

    Re: VBA Code to Pass String into Page Header

    Quote Originally Posted by rjj920 View Post
    ... code didn't work for me ...
    Ampersand (&) is missing in "G" => "&G" ... : )

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Code to Pass String into Page Header

    Try This:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    Excel 365
    Posts
    129

    Re: VBA Code to Pass String into Page Header

    Man, you're 2 for 2. This is close enough to where I can add spaces and format text now. Thanks for everything!

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA Code to Pass String into Page Header

    You're welcome and thanks for the rep!

    If that does it then please mark this thread as solved.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,694

    Re: VBA Code to Pass String into Page Header

    Put a TextBox on top of your picture, no lines, no fill. Center text in TextBox, horizontal and vertical, and group picture and TextBox. It'll be perfect in the center.
    Can all easily be done with code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Repeating the header at the start of each page with the page number
    By Viswateja in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-03-2017, 02:17 PM
  2. [SOLVED] Why does this code FIND the LAST string on the page?
    By CaptMac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-20-2016, 03:45 AM
  3. Trying to find & copy text string from page source code
    By LightingPop in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-16-2015, 09:24 PM
  4. Replies: 2
    Last Post: 10-21-2011, 04:13 AM
  5. Replies: 2
    Last Post: 01-16-2009, 05:24 PM
  6. [SOLVED] Can't insert a String Variable of Long Date into Page Header
    By Ronny Hamida in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2006, 12:45 PM
  7. [SOLVED] Get header only on first page of multi page excel file
    By betwms in forum Excel General
    Replies: 3
    Last Post: 03-29-2006, 12:50 PM

Tags for this Thread

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