views:

156

answers:

2

Hi,

i want do the following:

In Word 2007 place the Cursor on a field (or mark that field) and call a macro wich edit the field function of that field. (add some string).

I´m even grateful for some tipps what term to google.

I used the macro recorder and got following:

WordBasic.FormatField Field:="CITATION Gro05 \p 9 \l 1031"

Thats obvious creats a new field but where to go from here?

To get the selected field i thought about something like this:

If Selection.Type = WdFieldType Then ...

I hope someone give me some hints :) Bye Richard

A: 
Selection.Range.Fields

Will give you the collection of fields in the current selection.

Dennis Palmer
Thx i will try to work with that
Richard
A: 

Next Step, next Problem. Following Code should work, but i have a Problem with a Runtime Error "6124" which said the selection is protected (Debugger indicates rngTemp). I tried to unprotect and unlock ranges and the document but no change in behavior.

 Sub TestMakro()

 Dim functionString As String Dim
 rngTemp As Range Dim searchForThis As
 String Dim index As Integer

 searchForThis = "\f"

 If Selection.Range.Fields.Count > 0
 Then

 If Selection.Range.Fields(1).Type =
 wdFieldCitation Then  

    Set rngTemp = Selection.Range.Fields(1).Code

    functionString = Selection.Range.Fields(1).Code

    index = InStrRev(functionString, searchForThis)

        If index > 0 Then

        functionString = Mid(functionString, 1, index - 1)

        Else

        functionString = functionString & " \f ""vgl. """

        End If

      ' Tried to unprotected and unlock   '   
      If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
      Selection.Range.Fields.Locked = False
      rngTemp.Fields.Locked = False

      rngTemp.Text = functionString
      Selection.Range.Fields(1).Update

    End If

    End If
    End Sub
Richard
It looks like you've posted more information about your question as an answer. You should update your question instead.
Foole