Sub
Test()
Dim
aufvm
As
String
Dim
wert
As
Integer
Dim
rng
As
Range
With
ActiveDocument
ChangeFormfield
"AUFVMABETRAG"
,
False
If
FormfieldsExists(
"AUFVMABETRAG"
)
Then
aufvm = .FormFields(
"AUFVMABETRAG"
).Result
If
aufvm <>
""
And
Not
aufvm =
"0,00"
Then
ChangeFormfield
"AUFVMABETRAGT"
,
False
With
.FormFields(
"AUFVMABETRAGT"
)
.Result =
"hier kommt Text rein"
.Range.Font.Hidden =
False
End
With
wert = 1
Else
ChangeFormfield
"AUFVMABETRAG"
,
True
ChangeFormfield
"AUFVMABETRAGT"
,
True
End
If
Else
MsgBox
"Das Formularfeld AUFVMABETRAG ist im Dokument nicht vorhanden!"
, vbInformation
End
If
End
With
End
Sub
Sub
ChangeFormfield(FieldName
As
String
, ActionDelete
As
Boolean
)
Dim
lStart
As
Long
Dim
bk
As
Bookmark, Fld
As
FormField
With
ActiveDocument
If
ActionDelete =
True
Then
lStart = .FormFields(FieldName).Range.Start
.FormFields(FieldName).Delete
.Bookmarks.Add FieldName, .Range(lStart, lStart)
Else
Set
bk = GetBookmark(FieldName)
If
Not
bk
Is
Nothing
Then
lStart = bk.Start
bk.Delete
Set
Fld = .FormFields.Add(.Range(lStart, lStart), wdFieldFormTextInput)
Fld.Name = FieldName
Else
Debug.Print
"Die Textmarke "
& FieldName &
" ist nicht vorhanden!"
End
If
End
If
End
With
End
Sub
Function
FormfieldsExists(FieldName
As
String
)
As
Boolean
Dim
iFld
As
Integer
With
ActiveDocument
For
iFld = 1
To
.FormFields.Count
If
.FormFields(iFld).Name = FieldName
Then
FormfieldsExists =
True
Exit
Function
End
If
Next
End
With
End
Function
Function
GetBookmark(BkName
As
String
)
As
Bookmark
Dim
iCnt
As
Integer
With
ActiveDocument
For
iCnt = 1
To
.Bookmarks.Count
If
.Bookmarks(iCnt).Name = BkName
Then
Set
GetBookmark = .Bookmarks(iCnt)
Exit
Function
End
If
Next
End
With
End
Function