+ Reply to Thread
Results 1 to 4 of 4

Insert Function Result as Text

  1. #1
    Valued Forum Contributor ffffloyd's Avatar
    Join Date
    05-20-2008
    Location
    Melbourne, VIC, Australia
    MS-Off Ver
    Office 365
    Posts
    243

    Insert Function Result as Text

    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

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Insert Function Result as Text

    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]

  3. #3
    Valued Forum Contributor ffffloyd's Avatar
    Join Date
    05-20-2008
    Location
    Melbourne, VIC, Australia
    MS-Off Ver
    Office 365
    Posts
    243

    Re: Insert Function Result as Text

    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.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Insert Function Result as Text

    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1