Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    May 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Execute a Macro from a Field (Word 2000)

    How can I execute a macro from a field?
    If I have written a macro called 'MyMacro()', then
    I would like to execute it something like this:

    {MACRO MyMacro}

    The specific application is to make a macro which returns the string value
    of the current Word file's path. The DocProperty FileName (with the p switch)
    returns the complete path with the filename and '.' type appended. The
    FileName property without the p switch returns only the filename (without
    the .type appended). I want the directory path up to, but not including the
    filename and extension. I want to use this with the {INCLUDETEXT}
    field to append different filenames to the current doc file's path.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Execute a Macro from a Field (Word 2000)

    You were almost there: you need the MACROBUTTON field:
    { MACROBUTTON MyMacro Double Click Me }
    By default, you will have to double click this field. See http://www.mvps.org/word/FAQs/TblsFl...nksInForms.htm for a way to activate a MACROBUTTON field by a single click.

  3. #3
    New Lounger
    Join Date
    May 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute a Macro from a Field (Word 2000)

    Thanks. What I really want, though, is a way to execute the macro automatically.
    I suppose this could be done on exit or on save, but I'd like to reproduce the
    behavior of F9, which updates all fields. Is there any alternative to clicking on
    a MacroButton field?

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute a Macro from a Field (Word 2000)

    No field gets updated automatically, unless there is underlying code in Word or, say, an Event, that causes the field to get uodated without using, say F9.

    You could add code to, say, AutoClose, AutoExit to update all/particular fields, or you could use document events.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Execute a Macro from a Field (Word 2000)

    Let's see what the Word macro gurus have to say about this...

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Execute a Macro from a Field (Word 2000)

    Do you want your macro to execute when the user types F9, or every time a particular field is updated, or at some other time?

    (I don't have an answer for you, yet, but I want to make sure we are thinking about the right problem.)

    StuartR

  7. #7
    New Lounger
    Join Date
    May 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Execute a Macro from a Field (Word 2000)

    I want it to be updated along with everything else that is updated when I press F9.
    I'm trying to overcome a limitation of {INCLUDETEXT} which requires a full path
    specifier. I want the Word file to be moveable from one folder to another, so that
    the {INCLUDETEXT} tags will still be able to find the included files. What I really
    want to do is:

    {INCLUDETEXT "..SourceFilesSourceFileOne.c"}

    where the ".c" source files are to be embedded in the Word file, and can always
    be found one folder away in the directory tree from the Word file's folder. The
    Word file would be found in:

    C:MyDocsMyProjectWordFilesThisWordFile.doc

    and the included files would be found in:

    C:MyDocsMyProjectSourceFilesSourceFileOne.c
    C:MyDocsMyProjectSourceFilesSourceFileTwo.c

    etc.

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Execute a Macro from a Field (Word 2000)

    Create a Macro called UpdateFields like this.

    Sub UpdateFields()
    MyMacro
    Selection.Fields.Update
    End Sub

    Sub MyMacro()
    MsgBox "It Works!!"
    End Sub

    This will get called when you type F9.

    StuartR

Posting Permissions

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