Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2016, 08:33 AM
jheymann jheymann is offline Create MID function for Word using VBA? Windows 10 Create MID function for Word using VBA? Office 2013
Novice
Create MID function for Word using VBA?
 
Join Date: Aug 2016
Posts: 1
jheymann is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 08-15-2016, 04:54 PM
macropod's Avatar
macropod macropod is offline Create MID function for Word using VBA? Windows 7 64bit Create MID function for Word using VBA? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 08-15-2016, 09:19 PM
Guessed's Avatar
Guessed Guessed is offline Create MID function for Word using VBA? Windows 10 Create MID function for Word using VBA? Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,975
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
Reply

Tags
user defined functions



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create MID function for Word using VBA? Restrict Editing function disable insert textbox function IanM_01 Word 5 11-21-2015 02:29 AM
Create MID function for Word using VBA? #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
Create MID function for Word using VBA? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft