How to Download Images to Sharepoint with Excel VBA

Contributor

Good Morning

I created a form in Microsoft Forms, where they send me some images.

When I access the excel file that Forms creates so I can see the results, the fields of the images, have a link to open the images in the browser.

If I copy the link to the browser, it opens the image.

When I create a Userform in Vba for the images to appear in the image control and I load the images, the images are downloaded to my PC and then Vba shows them in the image controls.

But, the images he downloads is nothing more than a black background. Why? What am I doing wrong?

If I instead of trying to pull images that are in Sharepoint, I use image links from the internet, it downloads the correct image and shows it in Userform.

 

Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
    ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Sub CommandButton1_Click()
    Dim imgsrc As String
    Dim dlpath As String
    imgsrc="https://static.kbb.com.br/Uploads/ResearchTools/News/3099/31b6ebf5-06f6-42d0-91d8-b5e6aae08a35_1365x1024.jpg"
    dlpath = "C:\Meu_Backup\"
    URLDownloadToFile 0, imgsrc, dlpath & "HK Skyline.jpg", 0, 0
    Form_01_Entrada.MultiPage1.Pages(2).Image4.Picture = LoadPicture("C:\Meu_Backup\HK Skyline.jpg")
End Sub

 

0 Replies