# Excel Macro for download files from sharepoint to local



## gourishjoshi (Oct 24, 2012)

I am looking for help to create Excel Macro for download files from sharepoint to local.

Or i need to count the number of files are in each folder on sharepoint.

Thanks,


----------



## draceplace (Jun 8, 2001)

Welcome to TSG, hope you find some help and take the time to help others when you get a chance. Thats how the community here works best!

I've pull some files from share point and one thing that makes it much easier is to have WebDav enabled. This allows you to look a folders in share point. To see if its enabled use a path something like this in File Exployer.

\\XXXshare\DavWWWRoot\Folder1\QA\Consumers

A lot depends on what version of sharepoint your using, how it was implemented and what permission you have. But once you get the navigation going correctly it can be treated like any folder structure. Be warned that if users have alert settings in sharepoint your data manipuluation could trigger massive emails indicating changes or deletes.

I'm confused on why you would want to use Excel as a driver for for file maintenance?


----------



## Keebellah (Mar 27, 2008)

Hi, just took a look at WebDav, looks good.

I use the following macro to open an excel file on our sharepoint as read only to read a sheet and when finished I close it


```
Dim fName as String
' store the fullpath and filde in the variable fName
fName = "https://< sharepoint link >/Folder/"FileName.ext"  ' Extension can be xls, xlsm, xlsx 
' File will be opened if it's availabel, else the macro stops .
On Error GoTo noFileFound
Set wb = Workbooks.Open(FileName:=fName, ReadOnly:=True)
Set ws = wb.Sheets("Sheet1")

GoTo ok2Continue

< your vba code here >

GoTo exitFunction

noFileFound:
Msgbox "File " & fName & " was not found!"

exitFunction:
Err.Clear
On Error Goto 0
End Function
```
Hope this helps to put you on the right track


----------



## gourishjoshi (Oct 24, 2012)

Thanks to both of you for replying my query.

I need to download multiple files from each folder. Becuase i am having in Wk1 folder 5 files, but don't no what are the file names. So if any file with *.xlsx, it should download to local.


Thanks in advance.


----------



## draceplace (Jun 8, 2001)

So is WebDav enabled in your invironment? Are you able to navigate or programatically connect to the desired folder\files from outside sharepoint? This is your first step. 

Then you want to 'spin' thru the folder and 'copy' the xlsx files to another location?


----------



## gourishjoshi (Oct 24, 2012)

Option 1) Yes want to copy the file from sharepoint to my local
Option 2) Yes i want count of the each folder how many files are uploaded

Thanks


----------

