0
votes

I tried to use the code I found https://sharepoint.stackexchange.com/questions/174690/open-file-in-a-sharepoint-list-via-vba

My goal is to save the document in the users temp folder and then open it. However I am getting

error 52

on the FileCopy line. I copied the sharepoint link directly off of the email link so it should be exactly accurate.

I referred to many questions on here regarding FileCopy Error 52, but was unable to find a relevant answer.

If it is possible to open the document without saving that would actually be preferable, but I cannot use the Microsoft Scripting Runtime as some individuals are on Macintosh computers that do not have that library. The solutions I found that were a straight open seemed to all require that which is why I am saving and then opening.

 Dim strFolder As String
 Dim strName As String
 Dim URL As String

 strFolder = Environ("temp")
 strName = "\QpiExport.xlsx"
 URL = "https://sharepoint.company.com/some/more/files/Shared%20Documents/QSPI%20Export/QpiExport.xlsx"

 If Dir(strFolder & strName) <> "" Then ' if the temp file already exists then delete it first
  VBA.SetAttr strFolder & strName, vbNormal ' remove any file attributes (e.g. read-only) that would block the kill command
  VBA.Kill strFolder & strName ' delete the file
 End If

 FileCopy URL, strFolder & strName
 Workbooks.Open strFolder & strName
1
You need a separator "\" between strFolder and strName. - Andy G
@Andy G Swapped it to be strFolder & "\" & strName, but I'm getting the same error - Emily Alden
You need to do it in all five places. Preferably, construct a variable. - Andy G
Added it to the start of strName. , same error. (Thank you though!) - Emily Alden
Print out the value of Environ("temp"), is it what it should be? I.e. a valid path that you can append a filename to? - Andy G

1 Answers

0
votes

Solved by someone at work:

I needed to use the following filepath for the sharepoint which differed from the web address.

  URL= "\\sharepoint.company.com@SSL\SomethingRoot\a\few\folders\Shared Documents\QSPI Export\QpiExport.xlsx"