简体   繁体   中英

VBA to open a particular excel file from an sharepoint folder

I want to open an Excel file which is stored in my SharePoint under the Folder

//Documents // Design //Excel //items.xlsx

I searched through Internet and came up with the below code. The Problem with the code is it is opening the "File open " Dialogue box in the local drive.

Can anyone, suggest me a code that I could work with and could open an Excel file from SharePoint

Here is what i tried, with the previous example tried in the Forum

Sub Share()
Dim S As Workbook
Dim WB As Variant

With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = "https://Sharepoint.de/Content/0030/default.aspx" & "/RootFolder=%2Fcontent%2F00008200%2FTeam%20Documents%2F02%20%2D%20Design%2F0001%20Design%2FExcel&FolderCTID=0x01200083BC38D90EC5674491B520CC48282737&View={28035ED9-59EF-42BE-BA4B-A36193C54539}&InitialTabId=Ribbon%2EDocument&VisibilityContext=WSSTabPersistence"

.AllowMultiSelect = False
.show

For Each WB In .SelectedItems
Set S = Workbooks.Open(WB)
Next
End With

If S Is Nothing Then Exit Sub

End Sub

Thanking you in advance

This SO article covers your question quite well. To access files within your filesystem (including network):

This method opens a certain workbook:

Workbooks.Open ("yourWorkbook.xls")

Documentation and examples for this method.

If you actually want to open the folder, u can use this:

Application.FollowHyperlink "FolderLocation"

Documentation for this method.

Edit:

Use the UNC path as described in This SO article. Add your file name to the path and access it with the methods from above.

You can substitute the Cells(RowCtr, 1).Value = f.Name from the sample code in the article with a simple Debug.Print f.Name to check the outcome.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM