0

I have an application working with MS Word (2007) OleContainer in Delphi 10.2. I copy/paste an image on it with following command:

Copy:

  vBmp:=iAssinatura.Picture.Bitmap;
  Clipboard.Assign(vBmp);
  Clip:=1;

Paste:

  dm.WordApp.ActiveDocument.ActiveWindow.Selection.Paste;

(I tryed this as well: dm.WordApp.Selection.Paste;)

However, when the PC runs MS Word 2016 or higher, paste commands (both above) return the following errors: "The remote procedure call failed" and "RPC server is unavailable"

I tryed declare Uses Office2010 and Word20100 instead Office2000 and Word2000, but without success. Has anyone experienced this problem and could help me to fix it?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Well, there are 9 years between those Word releases...things might just change. You can always try Visual Basic (for applications) to verify things should work. If something fails there as well, you'll have to find a different approach. – Sherlock70 Dec 29 '22 at 10:52
  • A few vague ideas: (a) maybe the problem is with what is selected in Word? I've had an application where paste worked nicely, until one day something unusual was selected (I think it was a diagram), (b) maybe you haven't called CoInitialize - https://docwiki.embarcadero.com/RADStudio/Tokyo/en/CoInitialize, (c) how do you create dm.WordApp? – Matthias B Dec 29 '22 at 15:07
  • Thank you, Matthias. a) field selected is the same, so much that both codes work fine in Word 2007 but not in 2016. I beleave this is a change in Paste command in Word 2016. b) i going to read about it; c) dm.WordApp:=CreateOleObject('Word.Application'); dm.WordApp.Documents.Open(DocEditor.vArquivo); dm.WordApp.Visible:=False; dm.WordApp.ActiveDocument.Sections.Item(1).Footers.Item(1).Range.Tables.Item(1).Cell(2,4).Range.Select; dm.WordApp.ActiveDocument.ActiveWindow.Selection.Paste; – Renato Braz Dec 29 '22 at 15:39

0 Answers0