Macro to grab data from file located on sharepoint

1nk3d

Board Regular
Joined
May 31, 2016
Messages
51
I need some help with a macro here. Currently I have a workbook that will copy data from several workbooks on a shared drive. The macro works fine, however it is designed for multiple units to utilize, so therefore I use some array formulas which really slow things down. What I would like to do is instead of having the array formulas to filter the data, have the macro copy the data from the books on shared drive and paste it over, depending on selection. Which would require a report not being able to be ran unless a unit is selected. Any advice, suggestions?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Re: Help with macro to grab data from file located on sharepoint

Could you please provide your code so we can suggest you better.
 
Upvote 0
Re: Help with macro to grab data from file located on sharepoint

Here is what I have for part of the code. I redacted the urls. This code repeats itself several times, as it pulls data from another workbook, the code and format is the same, the data is different.

Code:
Public Sub OpenPrevWeek()
Dim wkbMyWorkbook As Workbook
Dim wkbWebWorkbook As Workbook
Dim wksWebWorkSheet As Worksheet
Set wkbMyWorkbook = ActiveWorkbook
Workbooks.Open ("url here")

Set wkbWebWorkbook = ActiveWorkbook
Set wksWebWorkSheet = ActiveSheet
wksWebWorkSheet.Copy After:=wkbMyWorkbook.Sheets(Sheets.Count)
wkbMyWorkbook.Sheets(ActiveSheet.Name).Name = "PW"
wkbMyWorkbook.Activate
wkbWebWorkbook.Close
PW
End Sub
Sub PW()
'
' PW Macro
'
'
    Sheets("PW").Select
    Sheets("pwoutput").Visible = True
    Sheets("PW").Select
    Columns("B:B").EntireColumn.AutoFit
    Columns("A:A").EntireColumn.AutoFit
    Range("A3:BE25184").Select
    Selection.Copy
    Sheets("pwoutput").Select
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("pwoutput").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("PW").Select
    Application.CutCopyMode = False
    Application.DisplayAlerts = False
    ActiveWindow.SelectedSheets.Delete
    Application.DisplayAlerts = True
    Application.GoTo Sheets("Fri").Range("A1"), True
    OpenPWhoc
End Sub
 
Last edited:
Upvote 0
Re: Help with macro to grab data from file located on sharepoint

Try this code, I hope this will solve the problem.

Private Sub CommandButton1_Click()
Sheets("Sheet1").Select
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & ""
End With




NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
myExtension = "*.xls" ' Can change the file type
myFile = Dir(myPath & myExtension)
Do While myFile <> ""
Set wb = Workbooks.Open(Filename:=myPath & myFile)




With Workbooks(myFile)
With .Range("a2:BZ" & .Range("B" & .Rows.Count).End(xlUp).Row)
.Copy
End With
End With




wb.Close SaveChanges:=False
myFile = Dir
Loop
MsgBox "Task Complete!"
ResetSettings:
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True




End Sub
 
Last edited:
Upvote 0
Re: Help with macro to grab data from file located on sharepoint

I forgot to add that the only data I want to copy over would be data that matches column B on the data set to cell B5 on the current workbook.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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