Consulting

Results 1 to 9 of 9

Thread: Symble Macro deletes word.

  1. #1
    VBAX Newbie
    Joined
    Aug 2014
    Posts
    2
    Location

    Symble Macro deletes word.

    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

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Aug 2014
    Posts
    2
    Location
    looks good but for some reason it dose not show the red (192) color?

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    What you see is what .Color 192 produces. If you want red I suggest you change:
    .Color = 192
    to:
    .ColorIndex = wdRed
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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)
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by Paul_Hossler View Post
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •