VBA Import data from xlsx file on sharepoint

floggingmolly

Board Regular
Joined
Sep 14, 2019
Messages
167
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet on sharepoint and I need to import the data from the ALL sheet into a worksheet on my computer called ALIGNMENT. I tried a code I found online but it didn't work. Any help would be greatly appreciated. I would like for it to import the data from the sharepoint file then close that file once it's done.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Can you post the code you tried and tell us how it didn't work?
 
Upvote 0
Code:
Option Explicit

Public Sub OpenWebXLS()
' *************************************************
' Define Workbook and Worksheet Variables
' *************************************************
Dim wkbMyWorkbook As Workbook
Dim wkbWebWorkbook As Workbook
Dim wksWebWorkSheet As Worksheet

Set wkbMyWorkbook = ActiveWorkbook

' *************************************************
' Open The Web Workbook
' *************************************************
Workbooks.Open ("http://mysharepointsite.mysheet.xls")

' *************************************************
' Set the Web Workbook and Worksheet Variables
' *************************************************
Set wkbWebWorkbook = ActiveWorkbook
Set wksWebWorkSheet = ActiveSheet

' *************************************************
' Copy The Web Worksheet To My Workbook and Rename
' *************************************************
wksWebWorkSheet.Copy After:=wkbMyWorkbook.Sheets(Sheets.Count)
wkbMyWorkbook.Sheets(ActiveSheet.Name).Name = "Alignment"

' *************************************************
' Close the Web Workbook
' *************************************************
wkbMyWorkbook.Activate
wkbWebWorkbook.Close

End Sub
[\code]

The lines of code below give an error. I'm not sure if it can be changed to import the data to the sheet I run the code from? 

wksWebWorkSheet.Copy After:=wkbMyWorkbook.Sheets(Sheets.Count)
wkbMyWorkbook.Sheets(ActiveSheet.Name).Name = "MyNewWebSheet"
 
Upvote 0
Are the real path/urls for the files pretty long?
 
Upvote 0
No problem.

I work with Sharepoint regularly and the only time I've really had problems has been when the path/url was ridiculously long.

That was usually a company issue really, not a Sharepoint one.
 
Upvote 0
I'm getting an error at this line of code: wksWebWorkSheet.Copy After:=wkbMyWorkbook.Sheets(Sheets.Count)
It opens the sheet from the sharepoint site, but then I get an error at this point. Any suggestions?
 
Upvote 0
No problem.

I work with Sharepoint regularly and the only time I've really had problems has been when the path/url was ridiculously long.

That was usually a company issue really, not a Sharepoint one.
I thought I had it working but I get an error on this line of code wksWebWorkSheet.Copy After:=wkbMyWorkbook.Sheets(Sheets.Count) The sheet opens from sharepoint but it wont copy and save it. Any suggestions?
 
Upvote 0
This line wksWebWorkSheet.Copy After:=wkbMyWorkbook.Sheets(Sheets.Count) needs to change to
wksWebWorkSheet.Copy After:=wkbMyWorkbook.Sheets(wkbMyWorkbook.Sheets.Count)
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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