web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Download site usage da...
Power Automate
Answered

Download site usage data for all subsites under a site collection in SharePoint online

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi, All

 

Requirement:

One of the Cx had 40-45 subsites under a site collection. They have to download the site usage data separately from every subsite, merge data manually and create report which they can share with leadership.

Report contains site usage data –

  1. Number of views for each subsite in last 30/60/90 days
  2. Top viewed documents in each subsite

My Observations:

  • One stop export Not available in user interface for all site collections and subsites combined. Only it has for Site collections alone.
  • Graph API also provides data for site collections only.

Is there any approach with Desktop Flow ?

 

 

 

I have the same question (0)
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    I don’t know how to export the sharepoint data specifically, but PAD can navigate sharepoint, from what I understand. Once you can get it all to excel, PAD can open Excel and run a VBA Macro. So it would just be building out the VBA macro. 

  • SP-15050722-0 Profile Picture
    Microsoft Employee on at

    Hi @MichaelAnnis , getting all data into an excel itself is the manual task which needs to be automated. Manual task includes - download excel from each subsite and merge manually into one.  

     

    If you can confirm PAD can navigate and download files from each subsite in SharePoint?

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Yeah, so the second part would be all Excel VBA.  If they all have the same column set, I have a VBA macro I can post here tomorrow when I’m back at my computer.

     

    Pulling them all down should definitely be doable in PAD.  Try using the recorder, it should capture the UIs for you. I don’t know what pulling down the data looks like, but hopefully, each sub site is the same, and you can set it up in a loop, where the hardest part is navigating to each sub site and after that, all the same UIs are used to download the usage report. 

     

  • SP-15050722-0 Profile Picture
    Microsoft Employee on at

    All the report export has the same column set and have 4 tabs init. 

  • Verified answer
    MichaelAnnis Profile Picture
    5,727 Moderator on at

    Okay, then combining them will be super easy. Good luck setting up the export, my intuition tells me the recorder will get you 95% of the way there, and you will have to fiddle with how you are going to get to each page. 

  • Verified answer
    MichaelAnnis Profile Picture
    5,727 Moderator on at

    @SahadebPatro , create a file like this:

    MichaelAnnis_0-1639756311929.png

     

    Paste the below macro into it starting with "Sub CombineExcelFiles()" all the way to the end.  The assumptions built into this macro are that every workbook being combined has the same number of tabs, each tab has the same number of columns in the same order, and every tab has a title row.  If none of these assumptions are correct, you will have to play with it a little.  For example, if there is not a title row, change the red line below to read 'Rows("1:" & LR).Copy' instead of 'Rows("2:" & LR).Copy'.  Otherwise, you simply list all your excel files in A:B, and where you want the final product saved in E:F.  Best of luck!

     

     

     

    Sub CombineExcelFiles()
    '
    ' CombineExcelFiles Macro
    '

    '
    'get loop max (last row of filenames)
    Dim LoopMax As Long
    Range("A1").Select
    Selection.End(xlDown).Select
    LoopMax = Selection.Row

    'Define the string variables filepath and filename
    Dim strfilepath As String
    Dim strfilename As String

    'i is the loop index, we start at 2 and work until loop max; LR is last row, used throughout the loop; NWB is New Workbook used through Loop
    Dim NWB As Workbook
    Dim LR As Long
    Dim i As Long
    i = 2

    Do
    'define the filepath and filename
    Workbooks("CombineExcelFiles.xlsm").Activate
    strfilepath = Range("A" & i)
    strfilename = Range("B" & i)
    'open the workbook
    ChDir (strfilepath)
    Workbooks.Open filename:=strfilepath & "\" & strfilename
    'define sheet variables for later use
    Dim AMWS As Worksheet 'active master worksheet
    Dim ANWS As Integer 'active new worksheet to be copied to active master worksheet, but by index
    'If the LoopIndex (i) = 2, declare Master WorkBook (MWB)
    If i = 2 Then
    'indentify master workbook name as this will become the master for all other workbooks to be copied to
    Dim MWB As Workbook
    Set MWB = ActiveWorkbook
    Sheets(1).Activate 'make sure we are on tab 1
    Else 'if i <> 2
    'copy the rows from the new workbook and paste them in the master workbook
    'define New WorkBook (NWB)
    Set NWB = ActiveWorkbook
    'reactivate the master workbook
    Workbooks(MWB.Name).Activate
    'for each sheet in workbook (this assumes all combined workbooks have the same tabs and the same column set in each tab)
    For Each AMWS In MWB.Worksheets ' for each worksheet in the master workbook
    ANWS = AMWS.Index 'the active new worksheet is indexed by the active master worksheet
    Workbooks(NWB.Name).Activate
    Sheets(ANWS).Activate
    'get the last row (LR) of the new workbook
    Range("A1").Select
    Selection.End(xlDown).Select
    LR = Selection.Row
    'assuming a title row, copy all rows 2 through last row
    Rows("2:" & LR).Copy
    'go to master workbook
    Workbooks(MWB.Name).Activate
    Sheets(AMWS.Index).Activate
    'select first available cell in column A
    Range("A1").Select
    Selection.End(xlDown).Select
    Selection.Offset(1, 0).Select
    'paste all copied data in first available cell in column A
    ActiveSheet.Paste
    'remove alerts to stop copied rows from causing error and close the excel file - it is no longer needed
    Next 'closes the for each loop telling it to run through each worksheet copying the NWB worksheet to the MWB sheets
    Workbooks(NWB.Name).Activate
    Application.DisplayAlerts = False
    Workbooks(NWB.Name).Close
    Application.DisplayAlerts = True
    End If
    'increase loopindex (i) by 1
    i = i + 1
    Loop Until i > LoopMax 'Loop will stop when i hits a blank row in columns A & B
    'define the path and filename of the combined workbook
    Windows("CombineExcelFiles.xlsm").Activate
    Dim savefilepath As String
    Dim savefilename As String
    savefilepath = Range("E2")
    savefilename = Range("F2")
    'go back to Master Workbook and Save As with defined path and name
    Workbooks(MWB.Name).Activate
    ActiveWorkbook.SaveAs filename:=savefilepath & "\" & savefilename
    End Sub

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 262 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 167

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard