How to Download Images to Sharepoint with Excel VBA

%3CLINGO-SUB%20id%3D%22lingo-sub-2880668%22%20slang%3D%22en-US%22%3EHow%20to%20Download%20Images%20to%20Sharepoint%20with%20Excel%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2880668%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22%22%3EGood%20Morning%3C%2FP%3E%3CP%20class%3D%22%22%3EI%20created%20a%20form%20in%20Microsoft%20Forms%2C%20where%20they%20send%20me%20some%20images.%3C%2FP%3E%3CP%20class%3D%22%22%3EWhen%20I%20access%20the%20excel%20file%20that%20Forms%20creates%20so%20I%20can%20see%20the%20results%2C%20the%20fields%20of%20the%20images%2C%20have%20a%20link%20to%20open%20the%20images%20in%20the%20browser.%3C%2FP%3E%3CP%20class%3D%22%22%3EIf%20I%20copy%20the%20link%20to%20the%20browser%2C%20it%20opens%20the%20image.%3C%2FP%3E%3CP%20class%3D%22%22%3EWhen%20I%20create%20a%20Userform%20in%20Vba%20for%20the%20images%20to%20appear%20in%20the%20image%20control%20and%20I%20load%20the%20images%2C%20the%20images%20are%20downloaded%20to%20my%20PC%20and%20then%20Vba%20shows%20them%20in%20the%20image%20controls.%3C%2FP%3E%3CP%20class%3D%22%22%3EBut%2C%20the%20images%20he%20downloads%20is%20nothing%20more%20than%20a%20black%20background.%20Why%3F%20What%20am%20I%20doing%20wrong%3F%3C%2FP%3E%3CP%20class%3D%22%22%3EIf%20I%20instead%20of%20trying%20to%20pull%20images%20that%20are%20in%20Sharepoint%2C%20I%20use%20image%20links%20from%20the%20internet%2C%20it%20downloads%20the%20correct%20image%20and%20shows%20it%20in%20Userform.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3EPrivate%20Declare%20PtrSafe%20Function%20URLDownloadToFile%20Lib%20%22urlmon%22%20_%0A%20%20%20%20Alias%20%22URLDownloadToFileA%22%20(ByVal%20pCaller%20As%20Long%2C%20ByVal%20szURL%20As%20String%2C%20_%0A%20%20%20%20ByVal%20szFileName%20As%20String%2C%20ByVal%20dwReserved%20As%20Long%2C%20ByVal%20lpfnCB%20As%20Long)%20As%20Long%0A%0ASub%20CommandButton1_Click()%0A%20%20%20%20Dim%20imgsrc%20As%20String%0A%20%20%20%20Dim%20dlpath%20As%20String%0A%20%20%20%20imgsrc%3D%22https%3A%2F%2Fstatic.kbb.com.br%2FUploads%2FResearchTools%2FNews%2F3099%2F31b6ebf5-06f6-42d0-91d8-b5e6aae08a35_1365x1024.jpg%22%0A%20%20%20%20dlpath%20%3D%20%22C%3A%5CMeu_Backup%5C%22%0A%20%20%20%20URLDownloadToFile%200%2C%20imgsrc%2C%20dlpath%20%26amp%3B%20%22HK%20Skyline.jpg%22%2C%200%2C%200%0A%20%20%20%20Form_01_Entrada.MultiPage1.Pages(2).Image4.Picture%20%3D%20LoadPicture(%22C%3A%5CMeu_Backup%5CHK%20Skyline.jpg%22)%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2880668%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFiles%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOneDrive%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPermissions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
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