Word VBA - Unable to import image from SharePoint

Glenn Sanders 1 Reputation point
2022-12-07T02:46:32.903+00:00

This code works on one PC (PC1) but not another PC (PC2).

Sub INSERT_IMAGE_SharePoint()
Dim strPicName As String
strPicName = "http://MYCOMPANY.sharepoint.com/:i:/r/teams/myteam/toolfiles/test.png"
ActiveDocument.InlineShapes.AddPicture (strPicName)
End Sub

On PC1, the pic is inserted. On PC2, nothing happens. I.e., I don't get an error message. Instead, the image simply isn't inserted.

The issues SEEMS to be SharePoint related because trying to insert an image from a standard web page works fine on both PCs:

Sub INSERT_IMAGE_Web()
Dim strPicName As String
strPicName = "https://i.etsystatic.com/6861832/r/il/4ee5d0/2697957373/il_300x300.2697957373_7ujr.jpg"
ActiveDocument.InlineShapes.AddPicture (strPicName)
End Sub

Likewise, inserting a local image works fine on both PCs:

Sub INSERT_IMAGE_Local()
Dim strPicName As String
strPicName = " C:\Users\grtsmith\Desktop\test.jpg"
ActiveDocument.InlineShapes.AddPicture (strPicName)
End Sub

I’ve tried other code leading to the InlineShapes.AddPicture method but with the same result. For example, this one works on PC1 but not PC2:

Sub INSERT_IMAGE_SharePoint_test2()
Dim strPicName As String
Dim shpShape As InlineShape
strPicName = "http://MYCOMPANY.sharepoint.com/:i:/r/teams/myteam/toolfiles/test.png"
Set shpShape = Selection.InlineShapes.AddPicture(FileName:=strPicName, LinkToFile:=False, SaveWithDocument:=True)
End Sub

Likewise, this code works with PC1 but not PC2:

Sub INSERT_IMAGE_SharePoint_test3()
Dim strPicName As String
strPicName = "http://MYCOMPANY.sharepoint.com/:i:/r/teams/myteam/toolfiles/test.png"
ActiveDocument.Bookmarks("bookmark_image"). _
Range.InlineShapes.AddPicture _
strPicName, False, True
End Sub

Specs:

  • PC 1 = Dell 64-bit Windows 10 Enterprise; Word 2016 (16.0.5369.1000) MSO (16.0.5365.1000) 32-bit
  • PC 2 = Surface 64-bit Windows 10 Pro; Word 2016 MSO (Version 2211 Build 16.0.15831.20098) 32-bit

In both versions of Word, I have the same 6 Reference libraries open:

  • Visual Basic For Applications
  • Microsoft Word 16.0 Object Library
  • OLE Automation
  • Microsoft Office 16.0 Object Library
  • Microsoft Forms 2.0 Object Library
  • Microsoft Windows Common Controls 6.0 (SP6)

I've also compared the Word options on both PCs, and they seem identical.

Is there a different method (not inlineshapes) that may work? Or could there be a browser issue? Not that I'm the SharePoint site owner and am able to upload, download, etc. (and create libraries, set properties, etc.) on both PCs.

Thanks in advance for any suggestions!

Office Visual Basic for Applications
Office Visual Basic for Applications
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Visual Basic for Applications: An implementation of Visual Basic that is built into Microsoft products.
1,496 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.