+ Reply to Thread
Results 1 to 8 of 8

How to use a macro to open files from sharepoint?

Hybrid View

rizwanulhasan How to use a macro to open... 09-06-2024, 09:58 AM
romperstomper Re: How to use a macro to... 09-06-2024, 10:19 AM
rizwanulhasan Re: How to use a macro to... 09-06-2024, 11:21 AM
Artik Re: How to use a macro to... 09-06-2024, 06:03 PM
rizwanulhasan Re: How to use a macro to... 09-07-2024, 11:27 AM
rizwanulhasan Re: How to use a macro to... 11-02-2024, 08:31 PM
Artik Re: How to use a macro to... 11-02-2024, 08:41 PM
rizwanulhasan Re: How to use a macro to... 11-02-2024, 08:49 PM
  1. #1
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    960

    How to use a macro to open files from sharepoint?

    Hi all,

    Hope all are well.

    I am using below macro to open excel file from an online sharepoint link and its working successfully.

    Sub OpenAllExcelFilesInFolder()
        Dim folderPath As String
        Dim fileName As String
    
       folderPath = "https://myteams.gsk.com/sites/Serialisation Governance/Business Process Support/EU Data Errors in ATTP EMVS/Alerts/Test/"
       Workbooks.Open fileName:="https://myteams.gsk.com/sites/Serialisation Governance/Business Process Support/EU Data Errors in ATTP EMVS/Alerts/Alerts logs 2024/EMVS Alerts Log - Benelux 2024.xlsm"
    End Sub
    However, there are 9 more files to be opened and therefore i modified the line as below to open 2 files at once.

    Workbooks.Open fileName:="https://myteams.gsk.com/sites/Serialisation Governance/Business Process Support/EU Data Errors in ATTP EMVS/Alerts/Alerts logs 2024/EMVS Alerts Log - Benelux 2024.xlsm","https://myteams.gsk.com/sites/Serialisation Governance/Business Process Support/EU Data Errors in ATTP EMVS/Alerts/Alerts logs 2024/EMVS Alerts Log - Scanda 2024.xlsm"
    But now the code doesn't work. Can someone please help how to add code for multiple files? Thanks in advance.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: How to use a macro to open files from sharepoint?

    You can't do that. Just repeat the Workbooks.Open line and change the file name each time. You could also put the filenames into an array and loop through that.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    960

    Re: How to use a macro to open files from sharepoint?

    Perfect. Repeating the Workbooks.Open code.

    Thanks a bunch

  4. #4
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,543

    Re: How to use a macro to open files from sharepoint?

    Instead of writing a long path in each file, consider using the following macro:
    Sub OpenAllExcelFilesInFolder()
        Dim folderPath As String
        Dim vFiles As Variant
        Dim i As Long
    
        folderPath = "https://myteams.gsk.com/sites/Serialisation Governance/Business Process Support/EU Data Errors in ATTP EMVS/Alerts/Alerts logs 2024/"
    
        vFiles = Array("EMVS Alerts Log - Benelux 2024.xlsm", _
                       "EMVS Alerts Log - Scanda 2024.xlsm", _
                       "File AAA.xlsm", _
                       "File BBB.xlsm", _
                       "File CCC.xlsm")
    
        For i = 0 To UBound(vFiles)
            Workbooks.Open fileName:=folderPath & vFiles(i)
        Next i
    End Sub
    Artik

  5. #5
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    960

    Re: How to use a macro to open files from sharepoint?

    @Artik.

    That's great. Thanks a lot

  6. #6
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    960

    Re: How to use a macro to open files from sharepoint?

    Hi Artik,

    Hope you are well.

    Sorry but can you just help with 1 additional step.

    After all files are opened, I want the code to take me back to sheet "Main Page" in the original file from where macro was run.

    Could you please add this line at the end? Many thanks in advance.

  7. #7
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,543

    Re: How to use a macro to open files from sharepoint?

    Is it enough to add
    ThisWorkbook.Activate
    ?

    Artik

  8. #8
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    960

    Re: How to use a macro to open files from sharepoint?

    Its working perfectly. Thanks a bunch for your lightning response

+ 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. Open files from sharepoint location sequentially and run macro before moving on
    By mpaxton78 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-19-2021, 09:34 AM
  2. [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
  3. [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
  4. Can't find and open files on a Sharepoint drive
    By p24leclerc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2015, 10:09 PM
  5. Open multiple excel files on sharepoint using VBA
    By BjarneP in forum Excel General
    Replies: 1
    Last Post: 02-03-2014, 04:44 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