Search code examples
excelvbams-wordheader

How can I transfer an image from a cell in Excel to the Word header (left) VBA


how to insert a picture which is in an Excel Celle (C1) by VBA in a new created Word document in the header without formatting(no cell color)?

logo.copy

Set objHeader = myDoc.Sections(1).Headers(1).Range
objHeader.Paste

thank you!


Solution

  • I believe you have the right idea, just have to use copypicture and pastespecial

    This is a snippet of my code that does basically the same thing I'm just using the shape object instead of a range.

    Set reportHeader = masterReport.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
    masterWorkbook.Worksheets("Template").Shapes("LogoSmall").CopyPicture
    reportHeader.PasteSpecial
    

    Thanks again to this post where I originally found this answer.