+ Reply to Thread
Results 1 to 10 of 10

open all excel files in a sharepoint folder

  1. #1
    Registered User
    Join Date
    03-20-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    4

    open all excel files in a sharepoint folder

    Hi All,

    I need to open all the excel files in a sharepoint folder using excel VBA code.

    i.e.., the excel file that i have will be the Master file .
    So , the Master file should open all the excel files in a sharepoint folder and copies and paste the values into the Master file and should close the excel files in Sharepoint.


    I tried using workbooks.CanCheckOut(xlFile).

    For this i have to give the exact file name.

    But what i need is to open automatically all the excel files in a sharepoint folder.

    All help is highly appreciated.

    Its very urgent.

    Thanks and Regards,
    Ish.
    Last edited by Ish23; 03-24-2011 at 04:39 AM. Reason: Did not get replies

  2. #2
    Registered User
    Join Date
    03-23-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    5

    re: open all excel files in a sharepoint folder

    Hi,

    I am trying to implement similar solution for my problem.Getting data from a workbook which is on my share point to an in memory data structure(array of my custom class)

    Can you please provide me the code which you have used yourself to get data from sharepoint.

    Thanks.

  3. #3
    Registered User
    Join Date
    03-20-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    4

    re: open all excel files in a sharepoint folder

    Hi,

    If you have list of *.xls files in sharepoint folder you can simply specify the path as below.

    'this code will be in a command button click event

    Private Sub Commandbutton1_click()
    Dim xlFile as string,xlFullFile as string
    Dim xlApp As Excel.Application
    Dim wb As Workbook


    xlFile = "\\**.**.**********.com\**\*************\**** ******** ****\**** ****"

    ****----denotes the path.(i.e) u give the path as windows search.Don't use "\" at the end.
    In the sharepoint path %20 denotes space.so u remove that and use space .

    Set xlApp = New Excel.Application
    xlApp.Visible = True

    xlFullFile = GetFullFileName(xlFile, "ANZ") 'ANZ denotes starting characters of the file.
    xlFile = xlFile & "\" & xlFullFile
    Set wb = xlApp.Workbooks.Open(xlFile, , False)

    'Once the workbook is opened u can do ur code here

    wb.close false





    Function GetFullFileName(strfilepath As String, _
    strFileNamePartial As String) As String

    Dim objFS As Variant
    Dim objFolder As Variant
    Dim objFile As Variant
    Dim intLengthOfPartialName As Integer
    Dim strfilenamefull As String

    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFS.GetFolder(strfilepath)

    'work out how long the partial file name is
    intLengthOfPartialName = Len(strFileNamePartial)

    For Each objFile In objFolder.Files 'Instead of specifying the starting characters of the file you can
    directly loop through all files in the folder .


    'Test to see if the file matches the partial file name
    If Left(objFile.Name, intLengthOfPartialName) = strFileNamePartial Then

    'get the full file name
    strfilenamefull = objFile.Name
    Exit For

    Else

    End If

    Next objFile

    Set objFolder = Nothing
    Set objFS = Nothing

    'Return the full file name as the function's value
    GetFullFileName = strfilenamefull


    End Function



    Hope this helps.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: open all excel files in a sharepoint folder

    Ish23

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    03-20-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: open all excel files in a sharepoint folder

    Hi,

    If you have list of *.xls files in sharepoint folder you can simply specify the path as below.

    'this code will be in a command button click event
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Hope this helps.

  6. #6
    Registered User
    Join Date
    02-18-2013
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: open all excel files in a sharepoint folder

    Were you able to solve your issue?. I have a similar need. If you were able to please provide code.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: open all excel files in a sharepoint folder

    mscurtin67,

    This thread is 2 yrs old and the original poster is not likely to come back and respond. Its better if you post a new thread for your question. You will get better visibility and faster replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  8. #8
    Registered User
    Join Date
    01-12-2016
    Location
    Birmingham,England
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Re: open all excel files in a sharepoint folder

    I am trying to run in a macro in a SharePoint excel document that copies values in standardised timesheets and pastes them into a master file in SharePoint.

    The code below works in my personal drive but not when I export the master file in SharePoint and run from within there.

    Can someone please help with the code below please:

    Sub LoopThroughDirectory()
    Dim MyFile As String
    Dim erow
    Dim Filepath As String
    Filepath = "//hub.bcu.ac.uk/sites/rie/cdc-work-area/Timesheet Test RESTRICTED Access"
    MyFile = Dir(Filepath)

    Do While Len(MyFile) > 0
    If MyFile = "Zmaster.xlsx" Then
    Exit Sub
    End If

    Workbooks.Open (Filepath & MyFile)
    Range("A59:AF59").Copy
    ActiveWorkbook.Close


    erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    ActiveSheet.Paste Destination:=Worksheets("sheet1").Range(Cells(erow, 1), Cells(erow, 35))

    MyFile = Dir

    Loop
    Range("D1").Select
    MsgBox "Process is Complete!"
    End Sub

    The output is Process is complete but I don't see any values in the Zmaster file

    Thanks

  9. #9
    Registered User
    Join Date
    01-12-2021
    Location
    india
    MS-Off Ver
    2013
    Posts
    1

    Re: open all excel files in a sharepoint folder

    Hi I am trying to loop through a sharepoint folder and perform some operation on the files present in that folder. I replaced the path with my sharepoint folder. it is saying path not found error. can you please help me, like how to connect to sharepoint folder in a loop.

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: open all excel files in a sharepoint folder

    Quote Originally Posted by Nikhil_Meni View Post
    Hi I am trying to loop through a sharepoint folder and perform some operation on the files present in that folder. I replaced the path with my sharepoint folder. it is saying path not found error. can you please help me, like how to connect to sharepoint folder in a loop.
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1