none
macro go after style text RRS feed

  • Question

  • I want write macro that put '!' end of line when I use of style call "my style".

    How am I do it?

    Wednesday, May 23, 2012 5:17 AM

Answers

  • How will "my style" be applied to the text?

    The easiest way would be to have a toolbar button (or Ribbon item) that would change the style of the currently selected paragraph and then add the "!" at the end of the paragraph.

    Something like this:

    Dim rgePara As Range
    
    Set rgePara = Selection.Range.Paragraphs(1).Range
    
    With rgePara
        'Remove ¶ from range
        .MoveEnd wdCharacter, -1
        'Apply style
        .Style = "Body Text"
        'Add !
        .InsertAfter ("!")
    End With

    Thursday, May 24, 2012 12:19 PM

All replies

  • How will "my style" be applied to the text?

    The easiest way would be to have a toolbar button (or Ribbon item) that would change the style of the currently selected paragraph and then add the "!" at the end of the paragraph.

    Something like this:

    Dim rgePara As Range
    
    Set rgePara = Selection.Range.Paragraphs(1).Range
    
    With rgePara
        'Remove ¶ from range
        .MoveEnd wdCharacter, -1
        'Apply style
        .Style = "Body Text"
        'Add !
        .InsertAfter ("!")
    End With

    Thursday, May 24, 2012 12:19 PM
  • That is way to create new button in my ribbon.

    Can I put this code in callback of exist style from styleGallery?

    Monday, May 28, 2012 2:05 PM
  • > That is way to create new button in my ribbon.

    I am sorry, I am not sure what you mean by this.

    > Can I put this code in callback of exist style from styleGallery?

    I do not think you can change the Style gallery behaviour, you would need to create your own, which is way to much work considering the little task you want to automate.


    Wednesday, May 30, 2012 12:33 PM