[Excel->Word] Filling in Word document adds unwanted special characters

Mahar92

New Member
Joined
Jan 25, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am building an invoice generator that fills in a word template based on values in an Excel table. It all works fine - except for the address, which contains these rectangle-shaped special characters in all address lines
but the first one:

1698131811253.png


The corresponding cell value in the Excel table is:

1698131938821.png


The address in the Word template is located in a table cell. Reading out the contents of the cell

VBA Code:
Debug.Print WordDoc.Tables(1).Cell(1, 1).Range

returns the following result in the Immediate window:

STEFES BAU GmbH
Pfalzburger Str. 85
28207 Bremen
Deutschland

The VBA code is as follows:

VBA Code:
                With WordDoc.Content.Find
                    .Text = "[" & ContainerHeader(LBound(ContainerHeader), h) & "]"
                    .Replacement.Text = Format(Replace(ContainerValues(i, h), Chr(10), vbNewLine), varTypes(1, h))
                    .Wrap = 1 '1 = wdFindContinue
                    .Execute Replace:=2  '2 = wdReplaceAll, '1 = wdReplaceOne
                End With

What can I do to remove these special characters? Does anyone know if this character has a Char code that I can use to remove it?

BTW: If I just straight copy the value from to the Excel cell to the Word document, the formatting is just fine:

1698132350752.png
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi mahar. The unseen characters are part of the table make up. You need to use the Clean function when transferring from Word to Excel
HTH. Dave
 
Upvote 0
Hi mahar. The unseen characters are part of the table make up. You need to use the Clean function when transferring from Word to Excel
HTH. Dave
Thanks for your answer. I am actually transferring from Excel to Word, not the other way around.
Tried the Clean function, which I did not have on my radar, but sadly it removes all of the line breaks and prints out the address in one line.

I did have success, though, by replacing "vbNewLine" with "vbCr":

1698150772902.png


So I am using
VBA Code:
Replace(ContainerValues(i, h), Chr(10), vbCr)
instead of
VBA Code:
Replace(ContainerValues(i, h), Chr(10), vbNewLine)
 
Upvote 0
My misunderstanding. Happy to hear that you got it sorted out. Thanks for posting your outcome. Have a nice day. Dave
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top