F
frogman
Scope:
Have user select some text and click macro button the first word
becomes a macro button and a bookmark is created for reference.
The problem is if the first word has some type of hyphen or comma after
it my code creates a field with a space tagged at the end. I want the
field to be just the word.
Sub TextToFieldPara()
Dim strBookMarkName As String
Dim strFirstWordInSentence As String
Dim intStringLength As Integer
strBookMarkName = "P_" & ActiveDocument.Range(0,
Selection.Paragraphs(1).Range.End).Paragraphs.count &
ActiveDocument.Range(0, Selection.Paragraphs(1).Range.End).Words.count
ActiveDocument.Bookmarks.Add Range:=Selection.Range,
Name:=strBookMarkName
strFirstWordInSentence = Selection.Words(1)
intStringLength = Len(strFirstWordInSentence)
If Right(strFirstWordInSentence, 1) = " " Then
strFirstWordInSentence = Left(strFirstWordInSentence,
intStringLength - 1)
End If
Selection.Fields.Add Range:=Selection.Words(1), Type:=wdFieldEmpty,
Text:="GOTOBUTTON " & strBookMarkName & " " & strFirstWordInSentence &
"", PreserveFormatting:=False
Selection.GoTo What:=wdGoToBookmark, Name:=strBookMarkName
End Sub
Have user select some text and click macro button the first word
becomes a macro button and a bookmark is created for reference.
The problem is if the first word has some type of hyphen or comma after
it my code creates a field with a space tagged at the end. I want the
field to be just the word.
Sub TextToFieldPara()
Dim strBookMarkName As String
Dim strFirstWordInSentence As String
Dim intStringLength As Integer
strBookMarkName = "P_" & ActiveDocument.Range(0,
Selection.Paragraphs(1).Range.End).Paragraphs.count &
ActiveDocument.Range(0, Selection.Paragraphs(1).Range.End).Words.count
ActiveDocument.Bookmarks.Add Range:=Selection.Range,
Name:=strBookMarkName
strFirstWordInSentence = Selection.Words(1)
intStringLength = Len(strFirstWordInSentence)
If Right(strFirstWordInSentence, 1) = " " Then
strFirstWordInSentence = Left(strFirstWordInSentence,
intStringLength - 1)
End If
Selection.Fields.Add Range:=Selection.Words(1), Type:=wdFieldEmpty,
Text:="GOTOBUTTON " & strBookMarkName & " " & strFirstWordInSentence &
"", PreserveFormatting:=False
Selection.GoTo What:=wdGoToBookmark, Name:=strBookMarkName
End Sub