none
Paste cell cause macro disable RRS feed

  • Question

  • Hi,

    Did anybody have this experience? I create a simple template with Word 2007.  There are a table and a command button in the template.  For testing, a message box will popup if the command button is clicked.  It works fine when the document opened.  Then I select all cells in a row( Not select a row.  Put mouse cursor in the first cell, hold left and drag to the last cell) and copy.  Go to another row.  Put cursor at the fist cell.  Right mouse click, pick Paste Cells(If a row selected, the popup menu will show Paste Rows).  After the paste, the command button no longer work.  It only happen after select cells -> copy -> Paste Cells.  It won't happen if select row -> copy -> paste row

    Tuesday, March 27, 2012 7:35 PM

Answers

All replies

  • It seems wrong event was fired.  I made a test.  Created a templated with a table and a command button called cmdTest. When a document create / opened basic on this template, there are 2 cmdTest_click() events. One is in ThisDocument module under the template, the other is in ThisDocument module under the document. I put a line <MsgBox "Event in template"> in the event under template and <MsgBox "Event in document"> in ThisDocument module under the document.  When I click the buton before I do Paste Cells, "Event in template" popup.  But after I do Paste Cells, "Event in document" is popup. So is it a bug of MS Word 2007?  And any suggestion?

    Tuesday, March 27, 2012 10:17 PM
  • Hi Tony,

    I'm trying to reproduce the question as you described. I have a few questions need you help clarify:

    1. I noticed you mentioned command button, I suppose you mean a command button in document body, added through Word Developer tab, Controls group. And not a command button in Word ribbon.
    2. I suppose you created template with dotm file extension, please confirm.
    3. I don't see two events in new document macro, would you please clarify?

    Once I can reproduce this is product defect, I will report it to product team.

    thanks and regards,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Saturday, March 31, 2012 3:00 PM
    Moderator
  • Hi Forrest,

    Thanks for reply.  I create a dotm templay.  In this tmeplate, I insert a table and a activeX control command button.  The click event of the button is in the ThisDocument module like this:

    Private Sub cmdTest_Click()
        MsgBox "Event in Template"
    End Sub

    Then I create a new document with this template and open the vba editer.  Two projects are list in the project browser.  One is Document1 (or other default new document name), the othe is the template.  There are ThisDocument mobules in both project.  cmdTest_Click() under Document1 is empty.  When I click the button before I do the Paste Cells,  "Event in Template" is popup.  And nothing happen when I click this button after I did the Paste Cells.  So I enter a line in that empty event <MsgBox "Event in Document">.  Then I got the message "Event in Document". 

    I found more today.  I put that line into the empty event before I do Paste Cells and run.  It popup "Event in Document" first and then popup "Event in Template".  So the code in template should be pended after the code in the current document.  The Paste Cells process stop this pending.

    Thanks and regards,

    Tony H

    Monday, April 2, 2012 4:58 PM
  • Hi Tony,

    From what I see this behavior works as designed.  The newly created document doesn't create its own cmdTest_Click() event handler at first. It inherites the macro from the template at first.  Only after we explictly add event handler for command button, <MsgBox "Event in Document"> I see the "Event in Document message."

    After the document command button has its own event handler, "Event in Document" always fires.  "Event in tempalte" never fire  again.

    Please let me kown if I missed something.

    best regards,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Tuesday, April 3, 2012 7:41 AM
    Moderator
  • Hi Forrest

    From my testing, before I do "Paste Cells", both events fired.  The event in current document fired first, then the event in template fired.  After I do "Paste Cells", only the event in current document fired.  My concern is why "Paste Cells" makes this change and how to solve this problem?

    Thanks a lot.

    Tony H 

    Tuesday, April 3, 2012 4:02 PM
  • Hi, Tony,

    Would you please share your workbook for testing purpose?  Skydrive is idea place for it.

    best regards,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Wednesday, April 4, 2012 1:48 PM
    Moderator
  • Hi Forrest,

    I upload 2 files to public folder under skydirve: http://www.skydrive.com.  The template is "test.dtom".  "Test.dcom" is the document created with this tamplate and I put code to the event in this document.

    Thanks

    Tony H

    Thursday, April 5, 2012 4:00 PM
  • Sorry, but we need a exact Skydrive url for the files. I cannot figure out where to download files till now.

    thanks.


    Forrest Guo | MSDN Community Support | Feedback to manager

    Thursday, April 5, 2012 4:20 PM
    Moderator
  • Sorry, I never use that before so I didn't know that.  I'll give you the link tonight.  I can't access the drive now since my company block it.

    Hi Forrest, the link is https://skydrive.live.com/#cid=D2775FE3D745CC49&id=D2775FE3D745CC49%21131

    Thanks

    Tony H


    • Edited by Tony H1997 Friday, April 6, 2012 3:48 PM
    Thursday, April 5, 2012 4:58 PM
  • Thank you Tony sending the files.  I tried them and did reproduce the behavior as you said.  However, I'm not sure the root cause of this.  The copy and paste may break the referenced template project.

    To find the root cause of this behavior fall into paid support scope and requires more in-depth level of support.  You can find various options from this link:  http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone.

    best regards,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Monday, April 9, 2012 7:25 AM
    Moderator