Cannot save file to Sharepoint Online using VBA (Permissions error)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 16:07:43

问题


This is one of my first times using VBA. I have a command button that is supposed to be saving a file as, to my sharepoint online documents page. I can use the "excel services" and save to that documents page from excel manually, but when i try the same in VBA it is saying I do not have permission. Below is the code I am using, any advice would be much appreciated!

Private Sub CommandButton1_Click()

    Dim path as string
    dim filename1 as string

    path = "https://xxxxxx.sharepoint.com/sites/xxxxx/Shared Documents"
    filename1 = Range("B3").text
    activeworkbook.SaveAs FileName:=path & filename1 & ".xlsx", _
                          FileFormat:=xlopenxmlworkbook

End Sub

回答1:


If your current file is in the same folder as the destination you would like to save in, try this change for the definition of path:

path = "https://xxxxxx.sharepoint.com/sites/xxxxx/Shared Documents/"

The missing final / in your code is causing the FileName argument to be invalid, because path & filename1 & ".xlsx" evaluates to

https://xxxxxx.sharepoint.com/sites/xxxxx/Shared Documents[filename1].xlsx

Which means if permissions weren't restricted on the /xxxxx folder you would have written a badly named Excel workbook in that location.


ALTERNATIVE SOLUTION


Potentially another solution for your problem. Save an empty workbook in the location you wish to save your new Excel files. Open the empty Excel file, and run your macro there. Change the path line to:

path = ActiveWorkbook.Path & "\"

Try this to see if it works instead. This is how I got around Sharepoint permissions problems.



来源:https://stackoverflow.com/questions/45039061/cannot-save-file-to-sharepoint-online-using-vba-permissions-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!