PDA

View Full Version : Symbol Carousel



Kion Zanfret
07-24-2014, 04:45 AM
Hello all,

So I'm working on a bit of vba code and I wanna use bill coan's symbol carousel code to cycle between letters/words on double click. The code is as follows


Sub symbolcarousel()
Select Case Selection.Fields(1).Code.Characters(29)
Case "W"
Selection.Fields(1).Code.Characters(29) = "I"
Case "I"
Selection.Fields(1).Code.Characters(29) = "W"
Case Else
End Select
End Sub


Macro button

{ MACROBUTTON symbolcarousel I}

Couldn't get the code to run, error message "The requested member of the collection doesn't exist". After trying many things to get it going, I tried making it again from another PC.

The code worked first time, but when taking it back onto the PC I was working on before it gives me the error again. Seems I can only get the code to run as long as I haven't created any Macro's on the PC I'm using previously?

Really lost on this and would appreciate any help

Thanks

gmaxey
07-24-2014, 06:13 AM
Works fine here. Based on the error, it sounds like your field code is not 29 characters long. Do you have a space before the "M...

Kion Zanfret
07-24-2014, 06:26 AM
Yes I do have a space before the M

gmaxey
07-24-2014, 06:50 AM
Hmm. Well you only have two collections available 1) The collection of fields at the selection and 2) the selection of characters in the field code. Something is missing.

Replace your code with this an see what happens:


Sub symbolcarousel()
Dim oFld As Field
On Error Resume Next
Set oFld = Selection.Fields(1)
If Not oFld Is Nothing Then
On Error GoTo 0
MsgBox Selection.Fields(1).Code.Characters.Count
If Selection.Fields(1).Code.Characters.Count > 28 Then
MsgBox Selection.Fields(1).Code.Characters(29)
End If
Else
MsgBox "There is no selected field"
End If
End Sub

Kion Zanfret
07-24-2014, 07:55 AM
Instead I get two msgboxes now, one saying "29" and one saying "I"

Curiously enough I opened the macro that wasn't working, it's now doing what it should be...still a little worried that it'll just stop again for no reason. A bit confused on why it works now (without any changes) and didn't earlier, not touched the code since I posted.

Well, while I've got a thread, now the macro is actually working I need to edit it


Sub SymbolCarousel()
Select Case Selection.Fields(1).Code.Characters(29)
Case "We"
Selection.Fields(1).Code.Characters(29) = "I"
Case "I"
Selection.Fields(1).Code.Characters(29) = "We"
Case Else
End Select
End Sub



So I think I know why this isn't working, obviously the selection field doesn't pick up the "We" and cannot change it back "I" due to it being a two letter word. How can I fix this?


EDIT: Nevermind the code has stopped working again...Will try making my own code for doing this instead
Thanks for your help

gmaxey
07-24-2014, 10:40 AM
Try:


Sub PronounCarosel()
Select Case Trim(Right(Selection.Fields(1).Code, Len(Selection.Fields(1).Code) - 28))
Case "I"
Selection.Fields(1).Code.Text = Replace(Selection.Fields(1).Code, Trim(Right(Selection.Fields(1).Code, Len(Selection.Fields(1).Code) - 28)), "We")
Case "We"
Selection.Fields(1).Code.Text = Replace(Selection.Fields(1).Code, Trim(Right(Selection.Fields(1).Code, Len(Selection.Fields(1).Code) - 28)), "You")
Case "You"
Selection.Fields(1).Code.Text = Replace(Selection.Fields(1).Code, Trim(Right(Selection.Fields(1).Code, Len(Selection.Fields(1).Code) - 28)), "They")
Case "They"
Selection.Fields(1).Code.Text = Replace(Selection.Fields(1).Code, Trim(Right(Selection.Fields(1).Code, Len(Selection.Fields(1).Code) - 28)), "I")
End Select
End Sub


change your field code { Macrobutton PronounCarosel I }

Kion Zanfret
07-24-2014, 11:01 AM
Thanks, I'll try it tomorrow when I'm back in work and let you know :)

Kion Zanfret
07-25-2014, 02:54 AM
Brilliant works perfectly, many thanks!