PDA

View Full Version : Symble Macro deletes word.



d4com
08-20-2014, 02:37 AM
Hi All

I have created a macro for a red cross that I want to use to mark a students work, my problem is that when I highlight the sentence and click my macro it replaces the sentence with the cross symbol, is it possible to have the symbol placed next to the highlighted sentence or word rather than replacing it. find the code I am using below:

Sub CrossImage()
'
' NewCross Macro
'
'
Selection.TypeText Text:=ChrW(10006)
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
With Selection.Font
.Name = "Segoe UI Symbol"
.Size = 11
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = 192
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
.Ligatures = wdLigaturesNone
.NumberSpacing = wdNumberSpacingDefault
.NumberForm = wdNumberFormDefault
.StylisticSet = wdStylisticSetDefault
.ContextualAlternates = 0
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub

macropod
08-20-2014, 03:07 AM
Try:

Sub CrossImage()
With Selection
.Collapse wdCollapseEnd
.TypeText Text:=ChrW(10006)
With .Font
.Name = "Segoe UI Symbol"
.Size = 11
.Color = 192
End With
End With
End Sub

d4com
08-20-2014, 06:06 AM
looks good but for some reason it dose not show the red (192) color?

macropod
08-20-2014, 12:22 PM
What you see is what .Color 192 produces. If you want red I suggest you change:
.Color = 192
to:
.ColorIndex = wdRed

Paul_Hossler
08-23-2014, 04:21 PM
Using Word 2010, I had to do this to get it the cross char to be red (either .Color or .ColorIndex would work, but .Color has more choices)




Sub CrossImage()
With Selection
.Collapse wdCollapseEnd
.TypeText Text:=ChrW(10006)
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
With .Font
.Name = "Segoe UI Symbol"
.Size = 11
.Color = wdColorRed
End With
.MoveRight Unit:=wdCharacter, Count:=1
End With
End Sub

macropod
08-23-2014, 08:48 PM
All it takes is a re-ordering of the code:

Sub CrossImage()
With Selection
.Collapse wdCollapseEnd
With .Font
.Name = "Segoe UI Symbol"
.Size = 11
'.Color = 192
.ColorIndex = wdRed
End With
.TypeText Text:=ChrW(10006)
End With
End Sub
Yes, ".Color has more choices", but the OP said he wanted "a red cross" and 'Color = 192' <> 'ColorIndex = wdRed'. I'll leave it to the OP to decide.

Paul_Hossler
08-24-2014, 04:44 PM
Your re-ordering is more logical

Either works, but as you said the OP did use .Color so I used .Color = wdColorRed = RGB(255,0,0)

.Color = 192 = RGB(192,0,0) which still kind of a dull red

Can you expand your solution a bit so that if I type after the red X, the original font properties are used? I inserted the red X and then wanted to add (note text)

macropod
08-24-2014, 05:45 PM
Can you expand your solution a bit so that if I type after the red X, the original font properties are used? I inserted the red X and then wanted to add (note text)
The simplest way of doing that is to insert an extra space after the 'x' before formatting it, then selecting that space afterwards. Anything you type there will revert to the previous font:

Sub CrossImage()
With Selection
.InsertAfter ChrW(10006) & " "
With .Characters.Last.Previous.Font
.Name = "Segoe UI Symbol"
.Size = 11
.ColorIndex = wdRed
End With
.Characters.Last.Select
End With
End Sub
However, I'm not sure what the point is. The OP apparently wants to mark wrong answers with a red X; he said nothing about typing anything afterwards.

Paul_Hossler
08-24-2014, 06:11 PM
he said nothing about typing anything afterwards.


But I want to.

I'm going to make several flavors of your sub and tie them to keystrokes to easily insert 'markers' and allow a possible note after the marker

Now that you've given me the basic structure I think I can customize it

Thanks again