Insert pictures by vba from an sharepoint folder

sjorsp99

New Member
Joined
Jul 26, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello,

I’m trying to insert pictures from a SharePoint folder to an Excel worksheet, but I’m having trouble getting the right path. The code is working fine in a local folder; it shows perfectly the pictures I have in the folder. Is it possible to load pictures from a shared folder?

The code I am currently using:

Sub HaalEnPlakFotos()


'Begin met HaalNamen
Dim fso As Object
Dim folder As Object
Dim file As Object
Dim picPath As String
Dim i As Long

picPath = "C:\Users\xxx\OneDrive - xxxx\Documents\Excel"
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(picPath)

i = 2
For Each file In folder.Files
If Right(file.Name, 4) = ".jpg" Then
Cells(i, "Q").Value = file.Name
i = i + 1
End If
Next file

'Ga verder met PlakFotos
Dim rng As Range
Dim cel As Range
Dim pic As Picture
Dim j As Long

Set rng = Range("Q2:Q" & Cells(Rows.Count, "Q").End(xlUp).row)

i = 2
j = 1
For Each cel In rng
If cel.Value <> "" Then
Set pic = ActiveSheet.Pictures.Insert(picPath & cel.Value)
With pic
.ShapeRange.LockAspectRatio = msoFalse
.Width = 300
.Height = 150
.Top = Cells(i, j).Top
.Left = Cells(i, j).Left
End With
If j = 1 Then
j = 8
Else
j = 1
i = i + 12
End If
End If
Next cel

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top