D
Dietmar Brueckmann
Hi,
I'd like to delete all the text from the begin of a document till the end of
the first Field:
_____________________________
Sub CreateTestDoc()
Application.Documents.Add
Selection.TypeText Text:="aslkfdj laskjf"
Selection.TypeParagraph
Selection.TypeText Text:="12345 "
Documents(1).Variables.Add "TestVar", "Text of TestVar"
Documents(1).Fields.Add Selection.Range, wdFieldDocVariable, "TestVar"
Selection.TypeText Text:=" 6789"
Selection.TypeParagraph
End Sub
Sub TestField1()
Dim aRange As Range
CreateTestDoc
Set aRange = Application.Documents(1).Fields(1).Result
aRange.MoveStart wdStory, -1
MsgBox "»" + aRange.Text + "«"
aRange.Delete
End Sub
_________________________________
MsgBox shows the espected text.
aRange.Delete fails with german error message "Bereich kann nicht bearbeitet
werden" what could be in english "The range couldn't be processed".
Also fails aRange.Text = ""
I've found a workaround:
aRange.Select
Selection.Delete
But the Delete kills also the space before "6789". MsgBox doesn't show it.
I've two questions:
1. what's the problem with aRange.Delete
2. how could I avoid deleting the space after the variable-field, I need it
Best regards
Dietmar
I'd like to delete all the text from the begin of a document till the end of
the first Field:
_____________________________
Sub CreateTestDoc()
Application.Documents.Add
Selection.TypeText Text:="aslkfdj laskjf"
Selection.TypeParagraph
Selection.TypeText Text:="12345 "
Documents(1).Variables.Add "TestVar", "Text of TestVar"
Documents(1).Fields.Add Selection.Range, wdFieldDocVariable, "TestVar"
Selection.TypeText Text:=" 6789"
Selection.TypeParagraph
End Sub
Sub TestField1()
Dim aRange As Range
CreateTestDoc
Set aRange = Application.Documents(1).Fields(1).Result
aRange.MoveStart wdStory, -1
MsgBox "»" + aRange.Text + "«"
aRange.Delete
End Sub
_________________________________
MsgBox shows the espected text.
aRange.Delete fails with german error message "Bereich kann nicht bearbeitet
werden" what could be in english "The range couldn't be processed".
Also fails aRange.Text = ""
I've found a workaround:
aRange.Select
Selection.Delete
But the Delete kills also the space before "6789". MsgBox doesn't show it.
I've two questions:
1. what's the problem with aRange.Delete
2. how could I avoid deleting the space after the variable-field, I need it
Best regards
Dietmar