mail merge column headers

S

sherobot

How do i only show the column headers from the excel file that I am mail
merging into word.

So instead of it saying

<<first_Name>>
it says
<<A>>
without taking out the header names in the excel file.
I'm trying to do it this way because some of the header names are so long it
messes up the formatting in the word document when I need to print out the
document with only the fields showing
 
P

Peter Jamieson

I don't know of a simple way to do it, assuming that the printed version
needs to match what the user will see.

You can try connecting using Word VBA OpenDataSource and alias all the field
names in the SQLStatement, but that statement has a maximum of either 255 or
511 characters and it will probably only take a few fields with long field
names to exceed that limit - plus, you then have a data source that the user
will probably not be able to filter or sort, or in WOrd 2007, edit the data
from Word. e.g., you might have something like:

Sub ConnectWithAliases()
ActiveDocument.MailMerge.OpenDataSource _
Name:="C:\blah\myxls.xls", _
sqlstatement:="SELECT S.first_name AS `A`, S.last_name AS `B` FROM
[Sheet1$] "
End Sub

(Make sure the quotes around A and B are backquotes, i.e. `` , not straight
quotes, i.e. ''
 
S

sherobot

hmm not sure I could use that because other people would need to work in the
file and don't know much excel. But the work around I found was to insert a
column above row 1(the long descriptive headings) and type in A, B, C
accordingly to match the alphabetized column headings. It just seems
redundant to have to do this. Then when I merge the file I turn off row 2(
the row with my descriptive headings)

Peter Jamieson said:
I don't know of a simple way to do it, assuming that the printed version
needs to match what the user will see.

You can try connecting using Word VBA OpenDataSource and alias all the field
names in the SQLStatement, but that statement has a maximum of either 255 or
511 characters and it will probably only take a few fields with long field
names to exceed that limit - plus, you then have a data source that the user
will probably not be able to filter or sort, or in WOrd 2007, edit the data
from Word. e.g., you might have something like:

Sub ConnectWithAliases()
ActiveDocument.MailMerge.OpenDataSource _
Name:="C:\blah\myxls.xls", _
sqlstatement:="SELECT S.first_name AS `A`, S.last_name AS `B` FROM
[Sheet1$] "
End Sub

(Make sure the quotes around A and B are backquotes, i.e. `` , not straight
quotes, i.e. ''

--
Peter Jamieson
http://tips.pjmsn.me.uk

sherobot said:
How do i only show the column headers from the excel file that I am mail
merging into word.

So instead of it saying

<<first_Name>>
it says
<<A>>
without taking out the header names in the excel file.
I'm trying to do it this way because some of the header names are so long
it
messes up the formatting in the word document when I need to print out the
document with only the fields showing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top