#1
|
|||
|
|||
Create MID function for Word using VBA?
We are using mail merge to create documents using fields from a database. We want to be able to show only a portion of the field (for example, the left three characters). For reasons beyond the scope of this discussion, we can't do this in the database, prior to sending the merge fields to Word.
Is it possible to use VBA to create the equivalent of a MID() function for word, so that I can use a reference something like {mid( mergefield, 1, 3) }? I've never done anything with VBA, but according to what I've seen, it is mostly designed to be invoked by user actions, not by function calls in the text. Before I spend a lot of time trying to learn how to use VBA, I thought I would ask the experts if what I wanted to do was even possible. If it isn't possible, can anyone think of another way to accomplish the goal (IE, in a merge field reference in word, somehow limit the resulting text to the first 3 characters)? Thank you. |
#2
|
||||
|
||||
What you're asking for isn't possible - VBA cannot create new field functions. If the field data are purely numeric, you could use Word's INT and/or MOD math functions to truncate them. Beyond that, you'd have to edit the data post-merge, bearing in mind that there will be no mergefields in the output and any bookmarks in the mailmerge main document will have been deleted from the output.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
It is possible to manipulate the SQL query used in the mailmerge connection to customise the fields available in the merge. Refer to this thread for the concept http://windowssecrets.com/forums/sho...om-merge-field
If your data source is Access then you could create a suitable query there and connect to that query instead.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Tags |
user defined functions |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Restrict Editing function disable insert textbox function | IanM_01 | Word | 5 | 11-21-2015 02:29 AM |
#REF! Error in calling VBA function disappears when function is copied | lcaretto | Excel Programming | 2 | 05-26-2014 07:19 PM |
Creating a graph for Future Value function (FV function) | bmoody | Excel | 2 | 11-06-2013 10:52 AM |
Word VBA: How to create a command button and trigger a function? | tinfanide | Word VBA | 2 | 12-02-2011 05:51 AM |
Is there a function on MS Word showing the lastest changes made on a word file? | _____ | Word | 2 | 10-30-2010 05:33 AM |