Is there a field that you can insert in a Word document (or any other method) to call a VBA function and insert its string result at that point in the document?
Is there a field that you can insert in a Word document (or any other method) to call a VBA function and insert its string result at that point in the document?
_______________
Floyd Emerson
Business Intelligence Consultant
Melbourne, Victoria, Australia
Have you looked at the MACROBUTTON field? That field can be used to run a macro. If you tell the macro to insert the string at the selection point, it'll be inserted immediately before the MACROBUTTON field. With a bit of tweaking, the code could easily-enough delete the MACROBUTTON field as well.
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
The thing is, I don't want to press a button or have to do anything else to initiate a macro each time the value changes.
In this specific case, I want to write a function that will return only the directory path on which a file is stored (i.e. sans filename) and I want it to change automatically when the path changes. At present, I am using the {FILEPATH \p} field and manually changing the font to "white out" the portion that is the actual filename, but that is less than ideal of course.
In the general sense, I would then like to be able to extend the idea to allow any function in principle to be able to provide text. There are so many ways of interacting with the Excel environment through VBA functions and subroutines; I thought there must be similar ways of doing so with Word.
You know, it would save a lot of bother if you said up front what it is you want to do. You asked whether there was a field that could automate a macro, so that's the question I answered.
What you're now asking doesn't require any particular field to exist in the document. The following code, if added to the document's template (eg Normal.dot/Normal.dotm), will add & maintain such a scheme for all of the template's documents whenever those documents are created or opened. The code uses a QUOTE field, but that's not really necesary. It's only used so that anything else in the footer doesn't get clobbered.
Please Login or Register to view this content.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks