+ Reply to Thread
Results 1 to 2 of 2

Open files from sharepoint location sequentially and run macro before moving on

Hybrid View

mpaxton78 Open files from sharepoint... 03-18-2021, 04:28 PM
dangelor Re: Open files from... 03-19-2021, 09:34 AM
  1. #1
    Registered User
    Join Date
    01-11-2011
    Location
    coventry, england
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question Open files from sharepoint location sequentially and run macro before moving on

    OK novice here whos knowledge is limited to whatever I can scrape together from advice online so go easy ;-)

    Looking to build something that will open each file in a given sharepoint location one at a time, run the macro in it (lets call it "Refresh"), save, close and only then move on to do the same with the next file in that same location until all are done.

    Sure it should be simple but I'm struggling to find anything useful I can pull together to make it work.
    Thanks

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: Open files from sharepoint location sequentially and run macro before moving on

    Possibly...
    Option Explicit
    Sub Test()
        Dim PathToFiles As String, AllFileNames As Variant, FileName As Variant
        
        'Pick folder with files
        With Application.FileDialog(msoFileDialogFolderPicker)
            .Show
            If .SelectedItems.Count = 0 Then Exit Sub
            PathToFiles = .SelectedItems(1) & Application.PathSeparator
        End With
        ' or use
        'PathToFiles = "your file path" & Application.PathSeparator
        
        AllFileNames = GetFiles(PathToFiles, "xlsx") 'change or remove extention
        
        For Each FileName In AllFileNames
            Workbooks.Open (PathToFiles & FileName)
            
            Call refresh
            
            Workbooks(FileName).Close SaveChanges:=True
        Next FileName
    End Sub
    
    Function GetFiles(sPath As String, Optional Ext As String) As Variant
        Dim sFileName As String
        With CreateObject("Scripting.Dictionary")
            If Len(Ext) = 0 Then
                Ext = "*.*"
            Else
                Ext = "*." & Ext
            End If
            sFileName = Dir(sPath & Ext, vbNormal)
            Do While Not sFileName = vbNullString
                .Item(sFileName) = Empty
                sFileName = Dir
            Loop
            GetFiles = .keys
        End With
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How do I only open folders and not specific files on macro using sharepoint
    By tweacle in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2020, 03:17 PM
  2. [SOLVED] Open excel and PDF files from sharepoint
    By shreeja178 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2016, 02:15 AM
  3. [SOLVED] Macro to Save Excel File to a SharePoint location and then e-mail that location in Outlook
    By NickyHavey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2016, 09:27 AM
  4. Tweak VBA to Move SharePoint Files to a Folder in Same Location
    By n_lindsey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-13-2014, 03:21 PM
  5. [SOLVED] Need help! Macro to open sequentially named files, copy and paste data into a master file
    By derrickk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-05-2013, 03:35 PM
  6. [SOLVED] Open all files in a SharePoint folder (Problem: Files open out of order)
    By holmstarrunner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2012, 10:13 AM
  7. VBA code to open excel files in sharepoint
    By Ish23 in forum Excel General
    Replies: 1
    Last Post: 03-23-2011, 10:21 PM

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