VBA loop to only open "New" documents on Sharepoint

abenny

New Member
Joined
Jul 10, 2017
Messages
5
How can I add to this code to only open SharePoint library documents that show "New"? The code works great for all documents.

Code:
Dim SummarySheet As Worksheet
Dim FolderPath As String
Dim NRow As Long
Dim FileName As String
Dim imgTitle As String
Dim WorkBk As Workbook
Dim SourceRange As Range
Dim DestRange As Range
Dim FolderName As String
Dim LR As Long

Set SummarySheet = Worksheets(3)

'Modify folder path when transferring between process owners
FolderPath = "//workspace.bsaconnect.com/fin/CaseManagement/PO Invoice Upload/"
'Nrow keeps track of where to insert new rows in the workbook
NRow = 1
'Call directory the first time pointing it to all excel files
FileName = Dir(FolderPath & "*.xls*")
'Loop until directory returns empty string
Do While FileName <> ""
    'Open a workbook in the folder
    Set WorkBk = Workbooks.Open(FolderPath & FileName)
   'Set the cell in column A to be the file
    'SummarySheet.Range("U" & NRow).Value = FileName
    'Set the range to be A1000 through W1000
    On Error Resume Next
    Set SourceRange = WorkBk.Worksheets(1).Range("A2:M300")
    On Error GoTo 0
    'Set the destination range
    Set DestRange = SummarySheet.Range("A" & NRow)
    Set DestRange = DestRange.Resize(SourceRange.Rows.Count, SourceRange.Columns.Count)
    'Copy over values from the source to the destination
    DestRange.Value = SourceRange.Value
    'Increase NRow so that data moves down
    NRow = NRow + DestRange.Rows.Count
    'Close source workbook
    WorkBk.Close SaveChanges:=False
    'Use Dir to get to the next file name
    FileName = Dir()
Loop
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,214,661
Messages
6,120,793
Members
448,994
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top