Send & Receive Issues

How to Control Spacing in Outlook HTML Emails Generated with VBA

Rana GarciaRana Garcia Nov 11, 2026 870 views

Question details

The user wants to eliminate extra blank lines when generating HTML emails in Outlook using VBA and needs a workaround for the VBA line-continuation limit when constructing long strings.

How to Control Spacing in Outlook HTML Emails Generated with VBA
Product
Microsoft Outlook
Device & OS
not provided
Scenario
Automating Outlook email generation using VBA where HTML formatting causes unwanted spacing and long HTML strings hit compiler limits.
Observed behavior
Generated emails contain unwanted blank lines between elements, and the VBA editor throws an error when too many line continuations are used to build the HTML body.
Before you start

Before modifying your VBA script, ensure you have a backup of your current code and a basic understanding of HTML tags to properly adjust line breaks and margins.

Solution 1Recommended

Use Break Tags and String Concatenation in VBA

Replace paragraph tags with break tags to remove extra blank lines, and concatenate multiple string variables to avoid VBA limits.

In HTML emails, paragraph tags inherently create block-level spacing. Swapping them for line break tags provides tighter control over line spacing. Breaking down long HTML segments into separate variables bypasses VBA's line-continuation constraints.

1
Replace paragraph tags with break tags

In your VBA HTML string, use <br> tags at the end of text lines instead of wrapping them in <p> tags. This prevents the email client from adding automatic block-level spacing.

2
Declare multiple string variables

Create separate string variables (e.g., part1, part2, part3) in your VBA module for different sections of your HTML email body.

3
Assign HTML chunks to variables

Break your long HTML string into smaller, manageable chunks. Assign each chunk to a variable without exceeding the VBA line-continuation limit.

4
Concatenate the strings

Combine the individual variables using the ampersand operator (e.g., strbody = part1 & part2 & part3) before passing the final string to the HTMLBody property of the Outlook MailItem.

Use Break Tags and String Concatenation in VBA
CSS Alternative: If you prefer keeping paragraph tags, you can use inline CSS (e.g., <p style='margin:0;'>) to strictly override the default margin spacing.
Free Microsoft Office alternative

Looking for a Lightweight Office Suite with Excellent Compatibility?

While Outlook handles your email automation, if you need an office suite that offers seamless compatibility with Word, Excel, and PowerPoint files without heavy subscription fees, WPS Office is an ideal choice. It's lightweight, free to use, and features a familiar interface.

  1. 1. Download the Installer: Visit the official WPS Office website to download the free installation package.
  2. 2. Install WPS Office: Run the downloaded file and follow the on-screen prompts to complete the installation.
  3. 3. Explore Macro Support: Open WPS Spreadsheets or Writer and explore the built-in VBA editor to automate your daily tasks.
Fully compatible with Microsoft Office formats (.docx, .xlsx, .pptx).Built-in robust Macro/VBA support for automating spreadsheet and document tasks.Lightweight design that runs smoothly even on older devices.All-in-one tabbed interface for streamlined document management.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the VBA compiler throw a 'Too many line continuations' error?

VBA has a strict limit on how many times you can use the underscore character to continue a single line of code, typically capping at 25 line continuations. Breaking the string into multiple variables or an array bypasses this limitation.

What is the difference between <p> and <br> in HTML emails?

The paragraph tag <p> is a block-level element that automatically adds margin space above and below the text. The line break tag <br> simply moves the text to the next line without adding extra vertical spacing.

Can I read the HTML email body from an external text file?

Yes, you can write your complete HTML code in a standard text file and use VBA's FileSystemObject to read the entire file's content into a single string variable, keeping your VBA code clean and avoiding line-continuation limits entirely.