0

Problem:

I've a .xlsx file with photos on the D column and ids of them on the C column. I would like to get all the photos in a seperate folder with their id as their name.

1 Answer 1

2

After a bit a research and modifying the code I found one working:

Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub enregistre_image()
    Dim Pict
    Dim chrt As ChartObject
    Dim name As String
    
    For Each Pict In Worksheets("Feuil1").Pictures
        Pict.CopyPicture
        W = Pict.Width
        H = Pict.Height
        name = Range(Pict.TopLeftCell.Address).Offset(0, -1).Text
        Set chrt = ActiveSheet.ChartObjects.Add(0, 0, W, H)
        Sleep 10
        Pict.CopyPicture
        chrt.Select
        ActiveChart.Paste
        chrt.Chart.Export ThisWorkbook.Path & "\images\" & name & ".jpg", "JPG"
        chrt.Delete
    Next Pict
End Sub

The sleep of 10 ms is intended to give enough time to the clipboard to not crash (are issues without it).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.