none
How many times the event WindowSelectionChange is fired with a Paste action? RRS feed

  • Question

  • Hi,

       I'm having trouble debugging my VBA template project, because I cannot spot the exact problem.

       I have several Rich Text Content Controls with LockContentControl= True and LockContents=False; all of them are grouped in a ContentControlGroup with LockContentControl = True.

       When I Paste something inside a RTFCC using the new Paste options of Word 2010 (the ones from the Gallery: OriginalFormatting, etc.) everything is Ok, but when I Paste using the normal Paste (Button or Shift+INS) I get this error:

    6197
    Comando del modello a oggetti non disponibile nell'evento corrente

    wich can be approssimatly translated in english:

    6197
    Command of objects model not available in current event.

    Of course I cannot find any documentation!

    I guess it as sometimg to do with my use of the WindowSelectionChange event because when debug goes there. But I do not understand what could be wrong and why there is a difference with the different way of pasting.

    I did this experiment, in a new document:

    • My class named clsEventApp:

     

    Public WithEvents App As Word.Application

    Private Sub App_WindowSelectionChange(ByVal sel As Selection)
    times= times + 1
    MsgBox "Ciao, for the " & times & " time!"
    End Sub

     

    • in a module:
    Public MyApp As clsEventApp      '
    Public times As Long

    Public Sub match()
    Set MyApp = New clsEventApp
    Set MyApp.App = Word.Application
    End Sub

     After some experimenting I found that after putting the selection in the desired location and start the Paste the WindowSelectionChange Event is triggered:

    • only 1 time outside a RTF CC, both with normal and with the options Paste;
    • 5 times if used inside a RTF CC and what is copied has also a CC with the normal paste;
    • 2 times if used inside a RTF CC and what is copied has also a CC with the options paste;
    • 3 times if used inside a RTF CC and what is copied is only text with the normal paste;
    • 1 time if used inside a RTF CC and what is copied is only text with the options paste.

    Can you explain me these differences?

    If I use the same approach with my template I see that the problem with the normal paste arise

    • the first time with only text pasted inside the RTF CC
    • the second time if what I try to paste inside the RTF CC has also a RTF CC.

    Sorry for the long post, but I'm unable to point to a simple situation.

    Thanks for any help, Lauro

    P.S.: I was forgetting to say that every thing is fine with word 2007!

     

     

     

     


    Monday, March 21, 2011 3:16 PM

All replies

  • Hello Lauro,

    Thanks for posting. Actually, I am not very familiar with VBA project. Would you mind simplifying a docm file/steps and sharing it with me? So I could use it on my side to reproduce this issue for further research.

    Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 23, 2011 9:54 AM
  • Hi Bessie,

        if I could upload a file would be easier. Is it possible? I don't see this feature in the forum.

       Anyway...

       In a new document project I create a

    1. new class: named "clsEventApp"
    2. new module
    code in the class:
    Public WithEvents App As Word.Application
    Private Sub App_WindowSelectionChange(ByVal sel As Selection)
     times = times + 1
    MsgBox "Ciao, for the " & times & " time!"
    End
    Sub

    code in the module:
    Public MyApp As clsEventApp
    Public times As Long
    
    Public Sub Start()
     Set MyApp = New clsEventApp
     Set MyApp.App = Word.Application
    End Sub
    

     

      Now in the nomal doument insert some RTF Content Control.

      Then you can do some experiment, after you run the macro Start: you can see how many times the event WindowSelectionChange  is triggered.

     

    These are my founding:

     

    Normal Paste:

     

    Inside a Content Control:

    3 times.

    5 times, if you copy also the Content Control.

    Outside a Content Control:

    1 time.

    4 times, if you copy also the Content Control.

    Options Paste:    

     

    Inside a Content Control:

    1 time.

    2 times, if you copy also the Content Control.

    Outside a Content Control:

    1 time.

    2 times, if you copy also the Content Control

    Why those differences?



    Wednesday, March 23, 2011 4:37 PM
  • Hello again Lauro,

    Thanks very much for following up with these code. I am able to use this code on my side. However, I cannot reproduce this issue. Actually, I inserted some Rich Text content controls into the document. What do you mean normal paste and options paste? What do you mean inside/outside a content control? copy/paste some text/a content control inside/outside a content control?

    Actually, I have done a simple test. The testing result in my side is two times if I copy/paste a content control inside/outside a content control by pressing ctrl+c and ctrl+v. It is one time if I copy/paste some texts inside/outside a content control.

    If there is any difference between us, just feel free to follow up. You also could share the file via http://skydrive.live.com. Have a nice weekend.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 25, 2011 9:37 AM
  • Dear Bessie,


           the code I sent to you will not cause any problem. I used it only to try to understand where the problem could be in my actually more complex situation.

          When I say Normal Paste I intend clicking on the Main Icon of the toglebutton Paste in the Clipboard Group ( or using SHIF+INS or CTRL+V); when I say Paste OPtions I intend using th new options offered by Word 2010 accessible in the expanding part of the previous togle button or in the ContextMenuText (The Gallery I mean).

         When I say inside CC I intend pasting something inside it; outside CC copyng samething in some other part of the document.

        I was very surprise to notice that If I use what I call Normal Paste the WindowSelectionChange is triggered more time then I use the Other way of pasting.

       It was strange that in my actual code the problem is arising only with what I call Normal Paste not with the other one, not with Word 2007.

     

       But I found something even more strange.

       I found that my code crashed if as first line in my

    Private Sub App_WindowSelectionChange(ByVal sel As Selection)
    
    

    I have

    If ActiveDocument.AttachedTemplate.Name <> "MyTemplate.dotm" Then Exit Sub
    

    but if instead I use this, everything is OK:

    Dim myTemplate As Template
    
    Set myTemplate = ActiveDocument.AttachedTemplate
    If myTemplate.Name <> "MyTemplate.dotm" Then Exit Sub
    
    But the two are not the same?

     

    By Lauro

     

      

     

    Friday, March 25, 2011 4:59 PM
  • Hello Lauro,

    From what you side, I can get a better understanding on this issue. However, since I am not able to see this issue on my side, I am afraid that this issue may be related to the other code on your side. I think you could test it by creating a simple VBA code on your side, and see if this issue also happens.

    For the first code block, I suggest you could use exception handling like one in this MSDN page: http://msdn.microsoft.com/en-us/library/5hsw66as(v=vs.80).aspx.

    Hope it helps you more or less. Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 29, 2011 6:01 AM