Add picture to Excel sheet by macros

Nikita Pelevin

Add picture to Excel sheet by macros

Hi!

I'm writing script that make a Excel file and write some information from the Assembly.

To add picture (logo) to the sheet I'm use this code:


 

With xlApp.ActiveSheet.Pictures.Insert(LogoPath)
        .Left = xlApp.ActiveSheet.Range("B1").Left
        .Top = xlApp.ActiveSheet.Range("B1").Top
        .Placement = 3
        .PrintObject = True
End With

And it worked good. But ActiveSheet.Pictures.Insert make link to the picture. And if I send this Excel file to another PC logo will be lost.
That why I try use this code:

Call xlApp.ActiveSheet.Shapes.AddPicture(LogoPath, msoCFalse, msoCTrue, 100, 100, 100, 100)

But logo doesn't insert. Excel file creates without it.
And I don't understand why.

Nikita Pelevin

RE: Add picture to Excel sheet by macros
(in response to Nikita Pelevin)

I'm found solution:

With xlApp.ActiveSheet.Shapes.AddPicture(LogoPath0100-1-1)
        .Left = xlApp.ActiveSheet.Range("B1").Left + (xlApp.ActiveSheet.Range("B1").Width - .Width) / 2 
        .Top = xlApp.ActiveSheet.Range("B1").Top + (xlApp.ActiveSheet.Range("B1").Height - .Height) / 2 
    End With