“This command is not available.” error occurs when trying to execute PasteAndFormat function

孤街醉人 提交于 2021-01-28 04:10:47

问题


I published the VSTO app, where I copy a Range with a formatted text.

On most users machines the application works properly while some users have the error "This command is not available." thrown whenever the following piece of code is being excetuded.

  var sourceDocument = Globals.ThisAddIn.Application.ActiveDocument;
  sourceDocument.Range().Copy();
  Document documentOld = new Document();
  documentOld.Range().PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting); //here the error occurs
  Document documentNew = new Document();
  documentNew.Range().PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting);

Could you recommend me something? Should I check any settings of the Word App on the User's machine?

Your help would be highly appreciated!

Thank you in advance!


回答1:


Seems like sometimes the PasteAndFormat / Paste Special in Word is disabled upon creating a new Document. This can be reproduced manually in Word opening a new document, copying something to the clipboard and checking the paste options menu:

What I do in order to counteract this, is to do a normal paste, then delete the content and then use the PasteAndFormat.



来源:https://stackoverflow.com/questions/62137325/this-command-is-not-available-error-occurs-when-trying-to-execute-pasteandfor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!