1


In an Excel vba script I try to copy a picture from Excel and paste it in my Word header with the following code:

Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.documents.Add

Set WRng = objDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range
WRng.Text = "Hello"     // Displays properly Hello in the header
Worksheets("Logos").Shapes("LogoToCopy").Copy    
WRng.Paste      // Server threw exception error

However I receive a Run-time error '-2147417851', The server threw an exception.

Copy/pasting a text works fine. Any idea how to copy an image from excel and to paste it in a Word header using VBA in Excel ? Thanks.

Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89

1 Answers1

2

OK, finally found it. Paste has to be replaced by PasteSpecial and Copy by CopyPicture:

Worksheets("Logos").Shapes("LogoToCopy").CopyPicture
WRng.PasteSpecial
Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89