i want to save the image together with excel file. Like this, this is my code converting vb report to word:

ActiveDocument.Shapes.AddPicture FileName:="" & App.Path & "\logo1.jpg", Left:=140, Top:=0, SaveWithDocument:=True

Is there an option on excel like "SaveWithDocument:=True"

Recommended Answers

All 7 Replies

try setting LinkToFile = False. Then the image should save with the document.

xlws.Pictures.Insert("" & App.Path & "\Clogo.jpg", False).Select

heres my code,
please, can you specify where to put that option..

something like this from your original post should work, in your excel file:

ActiveDocument.Shapes.AddPicture Filename:= App.Path & "\logo1.jpg", LinkToFile:= False, SaveWithDocument:= True, Left:=140, Top:=0, Width:=100, Height:= 100

You'll have to adjust Width and Height, I just threw some numbers in.

ActiveDocument.Shapes.AddPicture Filename:= App.Path & "\logo1.jpg", LinkToFile:= False, SaveWithDocument:= True, Left:=140, Top:=0, Width:=100, Height:= 100

sir this isnt working on excel...

Sir, this is generated by macro but it says: ActiveX component can't create object.
I just want to specify the location of an excel image.

Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet

    Set xlApp = New Excel.Application
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Worksheets(1)
    xlApp.Visible = True

    ActiveSheet.Pictures.Insert("" & App.Path & "\Clogo.jpg").Select
  ->Selection.ShapeRange.IncrementLeft 144
    Selection.ShapeRange.IncrementTop 45.75

    Set xlBook = Nothing
    Set xlApp = Nothing
    Set xlSheet = Nothing

Perhaps you need to include the index number of the image, Selection.ShapeRange(0).IncrementLeft 144

Thanks, this worked like a charm

Dim xlObj As Object

Set xlObj = xlWSheet.Pictures.Insert(App.Path + "\img1.jpg")
xlObj.Top = xlWSheet.Cells(3, 3).Top
xlObj.Left = xlWSheet.Cells(5, 5).Left

I am not sure if this will save the image together with the excel file, but image positioning is enough, i will just include the images on the same folder.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.