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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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