Jumping Sheep
2006-02-01 14:16:27 UTC
Hi
I am wanting to provide a means of copying formatted text from one
document into the text field of a protected document. By formatted
text I mean text that could include a tab stop.
Here is my code:
Public Sub SetTextInFF()
If Selection.FormFields.Count = 1 Then
'No textbox but a check- or listbox
MsgBox Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count >
0 Then
'MsgBox Selection.Bookmarks(Selection.Bookmarks.Count).Range.Text
Dim Ad As Document
Set Ad = ActiveDocument
Dim bm As Bookmark
Set bm = Selection.Bookmarks(Selection.Bookmarks.Count)
Dim doc As Document
Set doc = Documents.Open("C:\TextEditFF.doc", _
Visible = False)
doc.SelectAllEditableRanges
Dim r1 As Range
Set r1 = doc.Range
Ad.Activate
ActiveDocument.Unprotect
bm.Range.FormFields(1).FormattedText = r1
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
doc.Close
End If
End Sub
This does copy the text across (with tab stop) but unfortunately blots
out the text field. Other variations have ended up with the formatted
text within the bookmark but not the form field. If I just assign to
the text field result the formatting is lost.
Anybody seen a solution to this?
Out of interest, I am able to extract formatted text from a text field
and paste it into another document. Quite messy though.
I am wanting to provide a means of copying formatted text from one
document into the text field of a protected document. By formatted
text I mean text that could include a tab stop.
Here is my code:
Public Sub SetTextInFF()
If Selection.FormFields.Count = 1 Then
'No textbox but a check- or listbox
MsgBox Selection.FormFields(1).Name
ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count >
0 Then
'MsgBox Selection.Bookmarks(Selection.Bookmarks.Count).Range.Text
Dim Ad As Document
Set Ad = ActiveDocument
Dim bm As Bookmark
Set bm = Selection.Bookmarks(Selection.Bookmarks.Count)
Dim doc As Document
Set doc = Documents.Open("C:\TextEditFF.doc", _
Visible = False)
doc.SelectAllEditableRanges
Dim r1 As Range
Set r1 = doc.Range
Ad.Activate
ActiveDocument.Unprotect
bm.Range.FormFields(1).FormattedText = r1
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
doc.Close
End If
End Sub
This does copy the text across (with tab stop) but unfortunately blots
out the text field. Other variations have ended up with the formatted
text within the bookmark but not the form field. If I just assign to
the text field result the formatting is lost.
Anybody seen a solution to this?
Out of interest, I am able to extract formatted text from a text field
and paste it into another document. Quite messy though.