c# - trap paste event in excel and allow only pastespecial -
i developed excel template , come across following problem...
there scenarios have validate cell.hence format of cell must preserved.if user copies value different sheet template format of cell overwritten. there way trap paste event in excel , use pastespecial using c#
thanks in advance....
i googled out 2 3 days , find work around,before using code have check trust acess vba object model in macro setting....of excel run project..
//add macro module microsoft.vbe.interop.vbcomponent component = this.vbproject.vbcomponents .add(microsoft.vbe.interop.vbext_componenttype.vbext_ct_stdmodule); component.codemodule.addfromstring("sub paste_cell()" + environment.newline + "if msgbox(\"normal paste operation has been disabled. paste values (cannot undone), proceed?\", vbquestion + vbokcancel, gsappname) = vbok then" + environment.newline + "on error resume next" + environment.newline + "activesheet.pastespecial format:=\"text\", link:=false, displayasicon:=false" + environment.newline + "selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks:=false, transpose:=false" + environment.newline + "end if" + environment.newline + "end sub"); //trap paste event commondata.datasheet.application.onkey("^v", "paste_cell");
Comments
Post a Comment