VBA to access Sharepoint with excel VBA FileSystemObject - excel

I am trying to access a folder in Sharepoint that is secured (https). I am using a little VBA macro in excel that uses the file system object . see code below that was found in similar thread. the macro would open the .csv file in the folder and scan for a certain string.
Sometimes it would work but sometimes it would say 'path not found' in that case I would open the sharepoint site with Microsoft Explorer (browser) and then it all would have worked.
Now that explorer has been decommissioned I cannot open that path in explorer anymore .
any suggestion ? I know mapping/syncing the sharepoint would be another option but I want my tool to be used by different users and I guess mapping/syncing would make the new path , user dependent .
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(//companyname.sharepoint.com#ssl/sites/Invoices/Shared Documents/Tre/daily)
For each oFile in oFolder.Files
...etc etc.
thanks
Marthomas

While IE is not available from User Interface, you still can use it in macro, so it is possible to login to SharePoint using IE and work with SharePoint.

Related

Fetch values from HTML files to Excel sheet

I have multiple HTML files in my folder. I need to fetch some data from each html files and copy those value in excel sheet using VBA MACRO. how to write code to achieve this?.
And the html files should open in Microsoft edge browser (not in IE)
If any one knows the solution please help me out.
Thank you
You said,'the HTML files should open in Microsoft Edge browser (not in IE)'.
If your goal is to copy the data to an Excel sheet then I think it should not matter whether you are doing it via IE or Edge.
If you are thinking that as IE browser is retired on some Windows OS and your IE VBA Automation will not work then I would like to inform you that IE VBA automation will continue to work even after the IE browser retirement.
If you still want to automate the Edge browser then as suggested by the community member, you will need to use the web driver.
For VBA IE Automation the general idea would be to create an object of the IE or Edge browser from the Excel VBA editor. Launch the browser. Browse the web page. browse to the web element and copy the data to the Excel sheet.
If you use Selenium then you also need to use the library for Excel and create an object of the Excel file.
For more information, you could refer to the links below.
Use WebDriver to automate Microsoft Edge
Automate Microsoft Edge
Similar kinds of articles and docs you could find for the IE VBA Automation.
You could refer to the docs and try to make tests on your side. If you are stuck somewhere or have any questions. you could post a new question on this forum.

How to apply ThisWorkbook.SaveCopyAs with SharePoint path?

I have a line:
ThisWorkbook.SaveCopyAs Filename:="https://pmicloud-my.sharepoint.com/personal/yisaev_grintl_net/Documents/Book2.xlsm"
It returns an error:
"Sorry we couldn't find path [path string here]. Is it possible it was moved, renamed or deleted?"
Function .SaveCopyAs works with the path on a computer drive, but not with web site like SharePoint, when other options (Workbooks.Open and Workbooks.SaveAs) work with the same path to SharePoint.
Well excel wants to save the file to a hard drive. Saving to an URL is not the same thing.
The SharePoint URL is a web interface displaying data on a network drive. If you have access to that network drive you can directly save the file there.
Otherwise you will have to save the file and upload it manually.
Obviously Microsoft added some support for sharepoint over http(s), but it does not support the .SaveCopyAs method:
You can vote for this feature here:
Improve *Workbook.SaveCopyAs VBA method - support SharePoint / OneDrive

Unable to connect to Excel file in OneDrive

I've been searching and searching but with no luck. Is there a way to use Excel VBA to import master file data from another excel workbook saved in OneDrive?
Thanks in advance.
A.) If you have an excel workbook that is stored locally on your PC but inside your OneDrive sync-ed folder.Then you can use following VBA code to approach one drive file. Once file is available there are many routines already on SO to import data.
Sub Test()
Dim fn As String
fn = "Your File " 'change file name
fn = Environ("onedrive") & "\" & fn
'check to see if it exists
If Len(fn) > 0 Then
Debug.Print fn
End If
'... do something.......
End Sub
B.) FETCH FILES If you have the OneDrive desktop app for Windows installed on a PC, you can use the Fetch files feature to access all your files on that PC from another computer by going to the OneDrive website. You can even access network locations if they're included in the PC's libraries or mapped as drives. When you browse a PC's files remotely, you can download copies of them to work on. You can also stream video and view photos in a slide show. To access files on your PC remotely, make sure the PC you want to access is turned on and connected to the Internet. OneDrive also needs to be running on that PC, and the Fetch files setting must be selected. For further Details please refer Fetch files on your PC
C.) FIle on ShareOint - VBA aopproach If your file is on SharePoint. OneDrive doesn't sync the shared files to the local and sync. In such case VBA code is available on SO VBA download a File from OneDrive by #Sid29
D.)REST APIs - Microsoft Graph Another situation is elaborated in the following paragraph which uses API.
The OneDrive REST API is a portion of the Microsoft Graph API which
allows your app to connect to content stored in OneDrive and
SharePoint. The REST API is shared between OneDrive, OneDrive for
Business, SharePoint document libraries, and Office Groups, to allow
your app the flexibility to read and store content in any of these
locations with the same code.
These REST APIs are a part of the Microsoft Graph, a common API for Microsoft services.
For existing solutions using OneDrive API outside of Microsoft Graph, or solutions targeting SharePoint Server 2016, see direct endpoint differences for more context on reading this documentation. OneDrive and SharePoint in Microsoft Graph
E.) It may be difficult to get url of specific online file of onedrive. Microsoft Community has covered a situation where they have suggested VBA code for downloading of a file without URL.It is report xlsx from a web application.
Because the URL isn't the path to the file, it's a 'file request link' it processes single sign on verification, then the download popup is displayed.
Though it depends on the web site , code mentioned in article executed successfully using IE browser. Code mentioned in this article can be experimented with. There is no other method to load online onedrive file through VBA in my knowledge.

Deploy Add-ins saved on SharePoint across multiple computers

I am looking for a way where I can share a bunch of macros consolidated as an Add-in stored in a workbook that is saved as a .xlsm, with everyone in my department. I need to maintain full control of the workbook being used, so that no one can make changes to it, but if I make changes to the master copy it will automatically update all the ones used by all the people I am sharing it with. A shared drive deploy is out of the question due to access issues.
We are using SharePoint to control access to the workbook. I am wanting to do something similar to what's described in this link but using SharePoint instead of a shared drive.
Sub Auto_Open()
Workbooks.Open ("http://sharepointaddress/Workbookwithaddins.xlsm")
End Sub

XLViewer not working for XLSX attachments

I have users who want to open Excel attachments from a list item but sharepoint insists that it opens using xlviewer but it never works. There is always an error that says try again in a few minutes.
I just want to allow them to download it or to open it directly with excel or the associated application.
Make sure you're the site collection admin. Go into the site (not the central admin) and then go to site settings then go to site collection features. In there you will find the setting for " Open Documents in Client Applications by Default " it will probably be deactivated. Active it and you're good to go. users will then open attachments in their windows assigned applications, not the sharepoint web apps.

Resources