Excel VBA Problem Opening Sharepoint PDF

Dr_T

New Member
Joined
Dec 16, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi All

Really hope that someone can help with this. I've spent most of the day trying... and failing.

I have a few hundred PDF documents in a Shareholder folder and I'm looking to open them via an Excel hyperlink.

The code below works when the files are saved on my local drive, but fails when trying to open the Sharepoint version. If I was the only one accessing the files I'd just save them to my laptop, but there will be quite a few people in my company who will be using it.

VBA Code:
Function OpenAnyFile(strPath As String)
  Set objShell = CreateObject("Shell.Application")
  objShell.Open (strPath)

End Function

Sub Test() ' get PDF from Sharepoint folder
  Dim pdfPath As String
(Option 1 - works)    pdfPath = "C:\Users\me...\PDF Images\13110014.pdf"
(Option 2 - fails)    pdfPath = "\\mycompany.sharepoint.com\sites\Shared Documents\Forms\AllItems.aspx?id=\sites\sitename\Shared Documents\2013\11 November\13110014.pdf"
(Option 3 - fails)    pdfPath = "https://mycompany.sharepoint.com/sites/Shared%20Documents/Forms/AllItems.aspx?id=%2Fsites%2Fsitename%2FShared%20Documents%2F/2013/11 November/13110014.pdf" 
    Call OpenAnyFile(pdfPath)
End Sub

Any help would be very much appreciated!

Many thanks

Mark
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Sharepoint is not connected to your explorer, then it won't work.
So, try to sync the sharepoint folder to your explorer first, you should find that at sharepoint
 
Upvote 0
Have you tried:
pdfPath = "\\mycompany.sharepoint.com\sites\Shared%20Documents\Forms\AllItems.aspx?id=\sites\sitename\Shared%20Documents\2013\11%20November\13110014.pdf"
 
Upvote 0
Also, just notice in your option 3 there is a %20 missing between 11 and November...
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
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