none
shape selection operation is not recorded when recording a macro RRS feed

  • Question

  • Hi friends

    in Word 2013, via "record macro" tools, i am writing a macro which performs the following tasks for me:

    1- when i select a Phrase & the run the desired Macro, it  cuts that Phrase

    2-it then inserts a quick part object called "MyRectangle" in the same location which cut Phrase was before being cut ( i had created a customized rectangle shape & i had saved it as an Auto-text for later use)

    3- it then clicks on that Auto-text shape which was inserted ( that Auto-text be selected)

    4- finally it pastes that Phrase into that Auto-text Shape (Add the text inside that object)

    all above steps are done fine except step 3. the problem is when i start record macro, then it's not possible to select that rectangle shape ( i mean i left click on that rectangle but noting happens & it's not selected), so i can't paste that word into that shape.

    during record macro operation, can't we select shapes? if no, so what code i can write inside the macro for selection of that shape?

    the following is my Macro which lakes the step 3, and i need the code for step 3 or any better solution or macro 

    Sub MyMacro()
    '
    ' MyMacro Macro
    '
    '
        Selection.Cut
        Application.Templates( _
            "C:\Users\Administrator\AppData\Roaming\Microsoft\Templates\Normal.dotm") _
            .BuildingBlockEntries("small red box").Insert where:=Selection.Range, _
            RichText:=True
    End Sub

    Thanks in advance

    Wednesday, October 29, 2014 7:20 AM

Answers

  • You cannot record the selection of a shape via the macro recorder. If you have the shape selected beforehand, you can record some modifications of the shape, but that is not the same as recording its selection. In any event, if you know where the shape is, you can work on it without ever selecting it.

    For example, assuming your insertion point is located in the paragraph to which the shape is anchored, you might use something like:

    With Selection.Paragraphs(1).Range.ShapeRange(1)
      If .Type = msoTextEffect Then
        .Width = 241
        .TextEffect.Text = "Hello World"
      End If
    End With

    Of course, if you know which paragraph you want to work on, you don't even need to worry about selecting anything so you can have the insertion point located in the paragraph concerned. Indeed, if you know what you're doing, you don't even need to know what paragraph the shape is anchored to.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by john.s2011 Friday, October 31, 2014 10:02 AM
    Friday, October 31, 2014 9:21 AM

All replies

  • Cross-posted at: https://social.technet.microsoft.com/Forums/office/en-US/898d740b-ef57-46b2-ba76-49a48e89d7bb/shape-selection-operation-is-not-recorded-when-recording-a-macro?forum=word
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

    There are many things the macro recorder cannot capture, Shape selection is one of them. Instead of trying to capture complex actions via the macro recorder (which is generally very limited and inflexible), you need to write code that will do as you want.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, October 29, 2014 7:27 AM
  • Cross-posted at: https://social.technet.microsoft.com/Forums/office/en-US/898d740b-ef57-46b2-ba76-49a48e89d7bb/shape-selection-operation-is-not-recorded-when-recording-a-macro?forum=word
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

    There are many things the macro recorder cannot capture, Shape selection is one of them. Instead of trying to capture complex actions via the macro recorder (which is generally very limited and inflexible), you need to write code that will do as you want.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    thanks for advice.  i am a network administrator & really too busy to start learning VBA. but i need some macros in my daily works.

    i noticed that via select object pointer we can select that shape during recording macro & it worked.

    Thursday, October 30, 2014 11:07 AM
  • Hi john,

    >> i noticed that via select object pointer we can select that shape during recording macro & it worked.

    As far as I know, we can’t select shape in document body during recording. We need select it before start recording macro.

    Best Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 31, 2014 7:42 AM
    Moderator
  • Hi john,

    >> i noticed that via select object pointer we can select that shape during recording macro & it worked.

    As far as I know, we can’t select shape in document body during recording. We need select it before start recording macro.

    Best Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Hi Srarain

    off course we can. note the following screenshot:

    --------------------------------------------------------

    Please mark as answer or useful if it is.


    Friday, October 31, 2014 8:23 AM
  • Hi john,

    What I mean is select it directly. Actually, we can record the macro for the actions in ribbon(we can’t do actions directly in the document body)

    Best Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 31, 2014 8:33 AM
    Moderator
  • You cannot record the selection of a shape via the macro recorder. If you have the shape selected beforehand, you can record some modifications of the shape, but that is not the same as recording its selection. In any event, if you know where the shape is, you can work on it without ever selecting it.

    For example, assuming your insertion point is located in the paragraph to which the shape is anchored, you might use something like:

    With Selection.Paragraphs(1).Range.ShapeRange(1)
      If .Type = msoTextEffect Then
        .Width = 241
        .TextEffect.Text = "Hello World"
      End If
    End With

    Of course, if you know which paragraph you want to work on, you don't even need to worry about selecting anything so you can have the insertion point located in the paragraph concerned. Indeed, if you know what you're doing, you don't even need to know what paragraph the shape is anchored to.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by john.s2011 Friday, October 31, 2014 10:02 AM
    Friday, October 31, 2014 9:21 AM