Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8440293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:15:15+00:00 2026-06-10T08:15:15+00:00

I have a section of code that writes to the header section of the

  • 0

I have a section of code that writes to the header section of the page. The problem is that the string that is written to the header occasionally contains a ‘&’ symbol. This interferes with the code because VBA automatically views & and the following character as a piece of code, even if its part of the string.

ActiveSheet.PageSetup.CenterHeader = "&B&14 Cool New Header for &16 &I" & vbNewLine & aString

Everything works great when aString has no ‘&’ symbol in it. I get a bold, size 14 top line followed by the size 16, italicized aString text on a second line.

In the event that aString is something like ‘B&S Company of Greatness’ the header will come out with “Company of Greatness” stricken out because of the ‘&S’ contained within the string.

How can I get around this? I’d do a search in string for ‘&S and compensate manually by inserting another &S to cancel it out but &S might not be the only occurance of the ‘&’ symbol that occurs.

What’s the best way to get around this? Would properly diming things help by telling excel to read aString ONLY as a string value and to not apply its contents improperly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:15:16+00:00Added an answer on June 10, 2026 at 8:15 am

    You need to escape the ampersand by adding a second ampersand to each instance in the string, like this:

    aString = Replace(aString, "&", "&&")
    
    ActiveSheet.PageSetup.CenterHeader = "&B&14 Cool New Header for &16 &I" & _
        vbNewLine & aString 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a section of code that can be summarised as follows; void MyFunc()
I have the following section of code in an app that I am writing:
I have this view (DetailsContainer, first class in code section of this question) with
I have some VERY simple code to return the title for a section header:
I have problem running and debugging this piece of code: bool readSectionHeaders(char* path, int
I have data template dt1 in sitecore that has the field header in section
I have a piece of code written using VS 2005 that works fine in
So I'm having this piece of code that do horizontal scroll and I have
I have a bunch of code that's already written which currently relies on images
Javascript I have code that will hide various sections in a MS CRM form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.