Import Field Codes into Microsoft Word

Hi,
I am a newbie to this site and I really hope you can help me. My problem is this:

I have a software app that creates documents which works fine. The only problem is that I have to create the document template in Word. My app needs the fields in word to look like this {SNTEXT FirstName \ef <<NoData>> \eef}. So at the moment I have to create the field (Ctrl-F9) and physically type the code I need each time. I have tried mail merge but it removes the "\", puts the word MAILMERGE in the field code and some other stuff.

I also tried adding my new fields to the Word Quickparts but I don't think you can do that.

What I would really like is to be able to set up a list of all my codes (with a title if possible) and then simply add them to my document as fields. (oh...and to have the list available for new documents as well !!)

I know this is a tall order but any ideas or pointers on this would be gratefully received - otherwise its a weekend of typing in code!!!

Many thanks
JC
John CharlesworthAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
It is possible to create a field, select it and then add the selection to the Quick Parts Gallery.
Also you can add or edit a field with VBA, but I think we need more details of your situation.
0
John CharlesworthAuthor Commented:
Hi Graham. Blimey that was fast.....
I haven't been able to add a field into Quickparts.......probably user incompetence!

To try and explain further - I simply have a huge list of field codes (formatted as posted) and I somehow need to be able to add them to a Word document as easily as possible. As I said, the only way I have found to do this is to manually type them into the document. This has 3 drawbacks:
1. Its tedious
2. I make mistakes and only find them when I have loaded the report into my app and tested it
3. If I need to create another document I have to do it all again
I hope this helps and thanks for the fast response.
JC
0
GrahamSkanRetiredCommented:
Could the positions be determined automatically? This could be via bookmarks, pilot text or a particular table cell, etc.  If so, VBA could add the appropriate field from your list of fields content.

If you have to select the positions for the fields manually, you might find the Quick Parts route easier.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

John CharlesworthAuthor Commented:
Hi Graham,

No I have to place the fields manually.

JC
0
GrahamSkanRetiredCommented:
As I said, you should be able to add the fields to the QP gallery.

If you have the list of field codes in a Word document, you should be able to select each piece of text and create a field around it with Ctrl+F9
0
John CharlesworthAuthor Commented:
Hi,

Could you possibly give me some guidance as to how I would add these fields to the QP gallery? I have tried highlighting the manually created field in the document and then selecting "Save selection to Quick Part Gallery". The issue I have is my field is too long. Also, it wants to save it as a building block and not as a field. Must admit....I don't really understand the whole building block bit so is it just a case of more research?

Many thanks
JC
0
GrahamSkanRetiredCommented:
The quick parts gallery should be able to save anything that can be selected. I have copied your example to a document, selected it, used Ctrl+F9 the make it into a field and then saved it. It is given the default name of '*SNTEXT FirstName' and can be inserted anywhere that is then Selected.  

Of course Word thinks that it is a REF field and reports that it can't find the bookmark (SNTEXT).

If you still have problems, we might consider writing a custom macro that will insert the field from the list
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John CharlesworthAuthor Commented:
Hi Graham,

Many thanks for all your help. I have found out what I was doing wrong and can now save the fields in the Quickparts library. I will have a look online and see if I can get some ideas about maybe using a macro as per your suggestion. Thanks again
JC
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.