when the first word of the selection is a field (in this case a macrobutton) how to I test for that in my case statement 'sets the range and text to the first word of the selection if it is not a [ strTest = Selection.Words(1) Select Case Selection.Words(1) Case "[" Set rgeFirstWordInSentence = Selection.Words(2) Case "{[" Dim Answer As Long Answer = MsgBox("Is this action for the Brace ""{"" ?", vbYesNo, "Brace or Bracket") Select Case Answer Case vbYes Set rgeFirstWordInSentence = Selection.Words(2) Case vbNo Set rgeFirstWordInSentence = Selection.Words(3) End Select Case "{" Set rgeFirstWordInSentence = Selection.Words(2) Case strTest Set rgeFirstWordInSentence = Selection.Words(2) Case Else Set rgeFirstWordInSentence = Selection.Words(1) End Select
I used the code to copy the variable to the clipboard and pasted it into my case Public Sub CopyToClipBoard() 'This is how to clear the clipboard Dim MyData As DataObject Set MyData = New DataObject MyData.SetText "" MyData.PutInClipboard 'This is how to get the text from a string variable into the clipboard: Dim MyData As DataObject Dim strClip As String strClip = "Hi there" Set MyData = New DataObject MyData.SetText strClip MyData.PutInClipboard 'This is how to get the text on the clipboard into a string variable: Dim MyData As DataObject Dim strClip As String Set MyData = New DataObject MyData.GetFromClipboard strClip = MyData.GetText End Sub And this is the result Select Case Selection.Words(1) Case "[" Set rgeFirstWordInSentence = Selection.Words(2) Case "{[" Dim Answer As Long Answer = MsgBox("Is this action for the Brace ""{"" ?", vbYesNo, "Brace or Bracket") Select Case Answer Case vbYes Set rgeFirstWordInSentence = Selection.Words(2) Case vbNo Set rgeFirstWordInSentence = Selection.Words(3) End Select Case "{" Set rgeFirstWordInSentence = Selection.Words(2) Case " " blnIsField = True Set rgeFirstWordInSentence = Selection.Words(2) Case "[," Set rgeFirstWordInSentence = Selection.Words(2) Case Else Set rgeFirstWordInSentence = Selection.Words(1) End Select if there is a way to type this in that would be helpful too
Hi frogman, If all you need to do is find out what fields are within the selected range, you could use something like: Sub List_Fields() With Selection.Range For i = 1 To .Fields.Count MsgBox "Field " & i & ", Type: " & .Fields(i).Type _ & vbCrLf & "Code: " & .Fields(i).Code Next End With End Sub Cheers "frogman" wrote in message news:1129154191.527942.208820@g14g2000cwa.googlegroups.com... > when the first word of the selection is a field (in this case a > macrobutton) how to I test for that in my case statement > > 'sets the range and text to the first word of the selection if it > is not a [ > strTest = Selection.Words(1) > > Select Case Selection.Words(1) > Case "[" > Set rgeFirstWordInSentence = Selection.Words(2) > Case "{[" > Dim Answer As Long > Answer = MsgBox("Is this action for the Brace ""{"" ?", > vbYesNo, "Brace or Bracket") > Select Case Answer > Case vbYes > Set rgeFirstWordInSentence = Selection.Words(2) > Case vbNo > Set rgeFirstWordInSentence = Selection.Words(3) > End Select > Case "{" > Set rgeFirstWordInSentence = Selection.Words(2) > Case strTest > Set rgeFirstWordInSentence = Selection.Words(2) > Case Else > Set rgeFirstWordInSentence = Selection.Words(1) > End Select >