Been using API URLDownloadToFile for many years to download files from a SharePoint website, but we recently went to SharePoint ONLINE (on the CLOUD – not exactly the same as the old SharePoint server method) and it stopped working KIND OF. It still returns 0 (File downloaded OK), and a file is downloaded, but only a tiny part of the file is download; always 4kb in size for the pdf file we're testing with. The pdf file is about 10mg in size. Then Adobe DC gets a "cannot open file because it's not formatted correctly".

Note, if we open up IE and go to the SharePoint ONLINE site, then classic view, then select OPEN with FILE EXPLORER it "does something in the background" and the very same code and API URLDownloadToFile WORKS with NO CHANGES. A complete (10mg size) file is downloaded and works perfectly.

What VBA steps do I have to use before calling the URLDownloadToFile API to duplicate what the FILE EXPLORER is doing mysteriously in the background? It's just a file (not a SharePoint LIST) that we want to download from SharePoint ONLINE site and save automatically into a specific folder on the local laptop, then run word, excel, adobe dc to automatically open the downloaded file based on its file extension .doc, xlm, .pdf, etc.

Thanks so much in advance.